RAD Studio
ContentsIndex
PreviousUpNext
Bitwise Operators

Syntax

AND-expression &  equality-expression
exclusive-OR-expr ^ AND-expression
inclusive-OR-expr exclusive-OR-expression
~cast-expression
shift-expression << additive-expression
shift-expression >> additive-expression

Remarks 

Use the bitwise operators to modify the individual bits rather than the number.

Operator 
What it does 
&  
bitwise AND; compares two bits and generates a 1 result if both bits are 1, otherwise it returns 0.  
|  
bitwise inclusive OR; compares two bits and generates a 1 result if either or both bits are 1, otherwise it returns 0.  
^  
bitwise exclusive OR; compares two bits and generates a 1 result if the bits are complementary, otherwise it returns 0.  
~  
bitwise complement; inverts each bit. ~ is used to create destructors.  
>>  
bitwise shift right; moves the bits to the right, discards the far right bit and if unsigned assigns 0 to the left most bit, otherwise sign extends.  
<<  
bitwise shift left; moves the bits to the left, it discards the far left bit and assigns 0 to the right most bit.  

Both operands in a bitwise expression must be of an integral type.

A & B 
A ^ B 
A | B 
0  
0  
0  
0  
0  
0  
1  
0  
1  
1  
1  
0  
0  
1  
1  
1  
1  
1  
0  
1  

Note: &, >>, << are context sensitive. & can also be the pointer reference operator.
Note: >> is often overloaded to be the input operator in I/O expressions. << is often overloaded to be the output operator in I/O expressions.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!