Bitwise operators
Bitwise AND
Bitwise OR
Bitwise XOR (^^)
Bitwise Left Shift (<<)
Bitwise Right Shift (>>)
Important Notes
Last updated
Last updated
log 101 & 100
// 100log 101 | 100
// 101// Basic XOR operations
5 ^^ 3 // Returns 6 (binary: 101 ^^ 011 = 110)
12 ^^ 5 // Returns 9 (binary: 1100 ^^ 0101 = 1001)
// Common uses
// Toggle bits
flag = flag ^^ 1 // Toggles the least significant bit
// Swap variables without a temporary variable
a = 5
b = 3
a = a ^^ b // a = 6
b = a ^^ b // b = 5
a = a ^^ b // a = 3// Basic left shift operations
5 << 1 // Returns 10 (binary: 101 becomes 1010)
3 << 2 // Returns 12 (binary: 11 becomes 1100)
// Common uses
// Quick multiplication by powers of 2
num = 4 << 1 // Same as 4 * 2 = 8
num = 4 << 2 // Same as 4 * 4 = 16
num = 4 << 3 // Same as 4 * 8 = 32// Basic right shift operations
8 >> 1 // Returns 4 (binary: 1000 becomes 0100)
12 >> 2 // Returns 3 (binary: 1100 becomes 0011)
// Common uses
// Quick division by powers of 2
num = 16 >> 1 // Same as 16 / 2 = 8
num = 16 >> 2 // Same as 16 / 4 = 4
num = 16 >> 3 // Same as 16 / 8 = 2