Part of the Computing fundamentals glossary:

Bitwise data manipulation is working with data at the bit level, instead of working with bytes or larger units of data, as is more common. A bitwise operator (a character that represents an action, as for example x is an arithmetic operator that represents multiplication) manipulates single bits. In comparison, most operators work with either single or multiple bytes. Not all programming languages support the use of bitwise operators. C, JavaScript, and Visual Basic are among those that do. 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.

Next Steps

Because they allow greater precision, bitwise operators can make some code faster and more efficient. The following example, borrowed from Charity Kahn's article on CNET Builder.com (8/26/98), 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

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

 

Read more about it at:
> GameDev explains "Bitwise Operations in C."
> CNET Builder features Charity Kahn's article about "Bitwise Operators."
> SearchWin2000 offers a collection of Best Web Links for application and Web development.

This was last updated in May 2008
Posted by: Margaret Rouse

Related Terms

Definitions

  • glocalization

    - Glocalization is the concept that in a global market, a product or service is more likely to succeed when it is customized for the locality or culture in which it is sold.  (SearchCIO.com)

  • computer forensics (cyber forensics)

    - Computer forensics is the application of investigation and analysis techniques to gather and preserve evidence from a particular computing device in a way that is suitable for presentation in a cou... (SearchSecurity.com)

  • GPU (graphics processing unit)

    - A graphics processing unit (GPU) is a computer chip that performs rapid mathematical calculations, primarily for the purpose of rendering images. (SearchVirtualDesktop.com)

Glossaries

  • Computing fundamentals

    - Terms related to computer fundamentals, including computer hardware definitions and words and phrases about software, operating systems, peripherals and troubleshooting.

  • Internet applications

    - This WhatIs.com glossary contains terms related to Internet applications, including definitions about Software as a Service (SaaS) delivery models and words and phrases about web sites, e-commerce ...

Dig Deeper

People Who Read This Also Read...

Ask a Question. Find an Answer.Powered by ITKnowledgeExchange.com

Ask An IT Question

Get answers from your peers on your most technical challenges

Ask Question
  • Unable to browse local intranet PHP site

  • Subnet mask calculation

    My previous answer is wrong. /20 subnets increment is by 16, not by 6 as I stated before. Therefore, all addresses in your question reside in the same subnet. P.S.: How can I edit my previous post...

  • Difficult SQL query, is this possible?

    1) These tables were designed to have this type of logic used against them is it too late to go back and shoot the person who did this? it won't solve your problem, but it might make you feel bett...

Tech TalkComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.