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

#### Start the conversation

Send me notifications when other members comment.

## SearchCloudApplications

• ### What's in store for PaaS and data-driven apps?

Find out how Adam Gross, CEO of Heroku, sees PaaS infrastructure and data-driven apps evolving, and what it means for cloud ...

• ### What developers need to know about the Hyperledger Project

At DeveloperWeek, an IBM executive explains how blockchain efforts like the Hyperledger Project are going to change the way ...

• ### Find out exactly where the Docker Swarm architecture is heading

The challenge of provisioning applications across clusters remains a significant one. Docker's Mike Goelzer explains where the ...

## SearchSoftwareQuality

• ### Are you ready for the latest software testing trends?

From security to integration and flexibility, the software testing profession is undergoing more changes. Expert Matthew Heusser ...

• ### BizDevOps: Here's how to make it happen in your organization

With its roots firmly in Agile, BizDevOps is tomorrow's development methodology. Columnist Jennifer Lent explains why getting ...

• ### Change the culture to fix the tragedy that DevOps at scale can be

A DevOps effort always starts well and ends badly and sometimes even tragically. Expert Baruch Sadogursky explains why it's ...

## SearchFinancialApplications

• ### Workforce analytics software builds stronger ties to business outcomes

With data analytics tools, HR can measure aspects such as employee engagement and turnover of staff and use the results to become...

• ### Talent analytics plays a key role in motivating top performers

With the right metrics, organizations can use analytics to measure employee engagement and development initiatives as well as ...

A fast-growing automated investment provider uses Zenefits for hiring, onboarding and managing benefits and recommends the ...

## SearchSAP

• ### SAP S/4HANA Cloud deepens vendor's cloud offerings

SAP S/4HANA Cloud was unveiled at the Capital Markets Day event; 'next-generation intelligent' ERP aims to give large enterprises...

• ### SAP Hybris e-commerce fuels digital transformation for biotech firm

The SAP Hybris e-commerce platform and the back-end analytics tool Customer Insights Engine have helped the biotech firm Qiagen ...

• ### SAP EIM portfolio updates aim at improving data quality

SAP Enterprise Information Management (SAP EIM) portfolio has been updated to improve data quality, big data support, ease-of-use...

## SearchManufacturingERP

• ### Smart manufacturing technology is a dumb idea without good leadership

A manufacturing CEO explains why the IT-driven revolution in the factory won't amount to much without an educated, engaged ...

• ### Trump presidency makes supply chain disruption planning critical

The current political climate is a charged one. Companies that have a global supply network should start thinking about risks -- ...

• ### 3D printing company Carbon selects Oracle Cloud ERP

Carbon, a young company with an innovative new 3D printing technology, says using Oracle Cloud ERP for its business applications ...

Close