Bitwise Operations¶
Work with binary representations of numbers.
Bitwise Operators¶
let a = 12; // 1100 in binary
let b = 10; // 1010 in binary
// AND
print a & b; // 8 (1000)
// OR
print a | b; // 14 (1110)
// XOR
print a ^ b; // 6 (0110)
// NOT
print ~a; // -13
// Left shift (multiply by 2)
print a << 1; // 24
// Right shift (divide by 2)
print a >> 1; // 6