Bitwise Operators

1. Introduction

Operator Name Description
& Bitwise AND Sets each bit to 1 if both corresponding bits are 1.
| Bitwise OR Set each bit to 0 only if both corresponding bits are 0.
^ Bitwise XOR Sets each bit to 1 if only one of the corresponding bits is 1.
~ Bitwise Complement Inverts all bits (1's complement). Accepts one operand.
<< Left Shift Shifts bits to the left, filling with 0s on the right.
Multiplying by 22
>> Right Shift Shifts bits to the right, preserving sign (MSB remains the same for negative numbers).
Dividing by 22
>>> Unsigned Right Shift Shifts bits to the right, filling the left with 0s (ignores sign bit).
A B AND OR XOR Complement (~A)
0 0 0 0 0 1
0 1 0 1 1 1
1 0 0 1 1 0
1 1 1 1 0 0
Data Binary Shift Left Shift Right Shift Unsigned Right Shift
32 100000 (252^5) 1 bit 1000000 262^6 10000 242^4
32 100000 (252^5) 2 bit 10000000 272^7 1000 232^3
8 1000 (232^3) 1 bit 10000 242^4 100 222^2
8 1000 (232^3) 2 bit 100000 252^5 10 212^1
14 1110 1 bit 11100 0111
14 1110 2 bit 111000 0011
Type Val Val Val Val Val Val Val Val Val Val Val Val
Decimal 02 04 06 08 10 12 14 16 18 20 22 24
Binary 10 100 110 1000 1010 1100 1110 10000 10010 10100 10110 11000
Type Val Val Val Val Val Val Val Val Val Val Val Val Val
Decimal 01 03 05 07 09 11 13 15 17 19 21 23 25
Binary 01 011 101 111 1001 1011 1101 1111 10001 10011 10101 10111 11001

------ End ------