bitwise

Part of the TechTarget Network of Enterprise IT Web Sites

Search our IT-specific encyclopedia for:
 
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

>  Enterprise Software related Research & News
>  White Papers for the Retail Industry

Are you a Know-IT-All?
What technology is solid-state lighting based on?
Answer

word of the day Sign up for the Word of the Day
twitter Follow us on Twitter


WORD OF THE DAY...
above the fold
LEARN MORE ABOUT...
Mobile Web design and testing
wear leveling
write amplification
write endurance
decision management
business process governance
Profile-Driven Storage
Resilient File System (ReFS)
Security, Trust and Assurance Registry (STAR)
Windows Server 8
community cloud
managed storage
facial recognition
Shared serial-attached SCSI (SAS)
open compute project
BIOS password
dynamic BPM (business process management)
social BPM (business process management)
in-circuit emulator (ICE)
above the fold
logic simulator
photometric stereo
dynamic case management (DCM)
raw device mapping (RDM)
WhatIs.com RSS Feeds
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




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