JavaScript Bitwise Operations

JavaScript Bitwise Operations


JavaScript Bitwise Operations

Operator Name Description
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left shift Shifts left by pushing zeros in from the right and let the leftmost bits fall off
>> Signed right shift Shifts right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off
>>> Zero fill right shift Shifts right by pushing zeros in from the left, and let the rightmost bits fall off



32 Bits Bitwise Operands

Bitwise AND
One Bit Examples :
Operation Result
0 & 0 0
0 & 1 0
1 & 0 0
1 & 1 1

4 Bit Examples :
Operation Result
1111 & 0000 0000
1111 & 0001 0001
1111 & 0010 0010
1111 & 0100 0100


Bitwise OR
One Bit Examples :
Operation Result
0 ^ 0 0
0 ^ 1 1
1 ^ 0 1
1 ^ 1 0

4 Bit Examples :
Operation Result
1111 | 0000 1111
1111 | 0001 1111
1111 | 0010 1111
1111 | 0100 1111


Bitwise XOR
One Bit Examples :
Operation Result
0 ^ 0 0
0 ^ 1 1
1 ^ 0 1
1 ^ 1 0

4 Bit Examples :
Operation Result
1111 ^ 0000 1111
1111 ^ 0001 1110
1111 ^ 0010 1101
1111 ^ 0100 1011


>_ Sekian kalo ada salah mohon dikoreksi
Lebih baru Lebih lama