bitwise

Part of the TechTarget Network of Enterprise IT Web Sites
Home Look It Up ITKnowledge Exchange Fast References Products White Papers Blogs

Search our IT-specific encyclopedia for:
 
OR Jump to a topic:
 
Advanced Search
Browse alphabetically:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z #
All Categories Computing Fundamentals

bitwise

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.

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

 

OperatorNameTypeAction
&Bitwise ANDbinaryIf bits of both operands are ones, returns a one in each bit position
|Bitwise ORbinaryIf bits of either operand are ones, returns a one in a bit position
^Bitwise XORbinaryIf a single operand is a one, returns a one in a bit position
~Bitwise NOTunaryFlips the bits in the operand
<<Left shiftbinaryShifts first operand a number of bits to the left as specified in the second operand, shifting in zeroes from the right
>>Right shiftbinaryShifts first operand a number of bits to the right as specified in the second operand, and discards displaced bits
>>>Zero-fill right shiftbinaryShifts 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.
Last updated on: May 03, 2008

Are you a Know-IT-All?
The word pixel was created from two other words. What does pixel stand for?
 Answer

WORD OF THE DAY...
nonrepudiation
LEARN MORE ABOUT...
What IT jobs pay the most?
Buzzword Alert: Chrome
Our Favorite Cheat Sheets
Our Latest Discovery
57 technology-specific sites
WhatIs.com RSS Feeds
Home Look It Up ITKnowledge Exchange Fast References Products White Papers Blogs
About Us   |   Contact Us   |   For Advertisers   |   For Business Partners   |   Reprints   |   RSS   |   Awards
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts