Definition

bitwise operator

Contributor(s): Matthew Haughn

A bitwise operator is a character representing an action that works on data at the bit level rather than with bytes or larger units of data, as is more common.

In contrast, most regular operators work with either single or multiple bytes, which in most systems contain eight bits. Not all programming languages support the use of bitwise operators. CJava, JavaScript, Python and Visual Basic are among those that do. Because they allow greater precision and require fewer resources, bitwise operators can make some code faster and more efficient. Examples of uses of bitwise operations include encryption, compression, graphics, communications over ports/sockets, embedded systems programming and finite state machines.

A bitwise operator works with the binary representation of a number rather than that number's value. The operand is treated as a set of bits, instead of as a single number. Bitwise operators are similar in most languages that support them.

JavaScript Bitwise Operators:

 Operator Name Type Action & Bitwise AND binary If bits of both operands are ones, returns a one in each   bit position | Bitwise OR binary If bits of either operand are ones, returns a one in a bit   position ^ Bitwise XOR binary If a single operand is a one, returns a one in a bit   position ~ Bitwise NOT unary Flips the bits in the operand << Left shift binary Shifts first operand a number of bits to the left as   specified in the second operand, shifting in zeroes from the right >> Right shift binary Shifts first operand a number of bits to the right as   specified in the second operand, and discards displaced bits >>> Zero-fill right shift binary Shifts first operand a number of bits to the right as   specified in the second operand, discards displaced bits, and shifts in   zeroes from the left

Note: Left shift, right shift and zero-fill right shift are sometimes referred to as bit shift operators.

The following example compares two versions of JavaScript code used to map several form checkboxes to a single number:

var combo = form.elements[0].checked*(Math.pow(2,2))
+ form.elements[1].checked*(Math.pow(2,1))
+ form.elements[2].checked*(Math.pow(2,0));

Bitwise operators can be used to do the same thing, but more efficiently:

var combo = form.elements[0].checked << 2
| form.elements[1].checked << 1
| form.elements[2].checked << 0

This was last updated in July 2016

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

SearchCloudApplications

• BPM market advances around AI, cloud technology

As AI, microservices and other emerging technologies transform the BPM industry, enterprises need to carefully navigate their ...

• Serverless, containers shape future of cloud computing

Experts seem to agree that serverless platforms, containers and the eventual merging of the two will be the biggest cloud trends ...

• App development teams brace for big change in 2018

Multi-cloud, blockchain and more sophisticated PaaS tools are three trends expected to reshape app development practices in 2018....

SearchSoftwareQuality

• Atomist extends CI/CD to automate the entire DevOps toolchain

The Atomist DevOps automation platform extends beyond CI/CD to fully cover DevOps processes end to end, enabling developers to ...

• Why you should get on board with software testing trends

Will your organization design a machine learning app in 2018? Or should you pick up DevOps skills to be in demand as a tester? ...

• Agile and DevOps are better together in 2018

IT industry observers agree: When you add DevOps and Agile, you get more than the sum of the parts. See how experts envision the ...

SearchFinancialApplications

• Finance IT case study: Reporting secrets of Derek Rose

CEO Sacha Rose says specialist reporting tools have saved the company thousands by avoiding unnecessary mistakes.

• WestJet turns to gamification to help its Oracle ERP users soar

WestJet's initial gamification project focuses on expense reporting.

• The Transformation of HR is Underway

HR is being transformed while we watch.

SearchSAP

• SAP S/4HANA Cloud and indirect access will dominate 2018

Industry experts say SAP S/4HANA Cloud migrations, Leonardo and Cloud Platform are the technology issues for SAP in 2018; on the ...

• Enexis' citizen developers empowered by the Mendix RAD platform

When a Dutch energy grid provider needed to develop new business apps on top of SAP ERP, it turned to the Mendix RAD platform to ...

• SAP's Timo Elliott on enterprise chatbot AI technology

The SAP global innovation evangelist expects AI to affect businesses in three ways: human-computer interaction, automation of ...

SearchManufacturingERP

• ERP upgrade ushers in mobile apps, upends paper processes

An ERP upgrade sent a manufacturer's existing company culture into a tailspin. Would paper processes or digitization prevail?

• Fears about Prism's long-term impact on cloud declared "overblown"

Forrester claims the fallout from the 2013 Prism surveillance scandal has had a minimal effect on the cloud industry.

• Finding the right distribution inventory management plan

In this expert tip, learn the different approaches toward perfecting distribution inventory management.

DevOpsAgenda

• It's tough to explain DevOps, that nebulous IT concept

DevOps is more about goals and aspirations than any set of practices or tools. Right? Or is it just about collaboration and ...

• Four key lessons to apply from DevOps success stories

Take a DevOps team and make it a DevOps company. This is easier said than done, of course. Atlassian's Roger Barnes offers four ...

• It's critical to create the correct DevOps team structure

With new-to-DevOps enthusiasm, some companies go too far when it comes to creating teams or dividing responsibilities. Chris ...

Close