Hash Table
April 26, 2024
1 min
Only true if both input bits are true:
//0 & 0 = 0//1 & 0 = 0//0 & 1 = 0//1 & 1 = 1
True if any input bit is true
//0 | 0 = 0//1 | 0 = 1//0 | 1 = 1//1 | 1 = 1
True if one and only one input bit is true
//0 ^ 0 = 0//1 ^ 0 = 1//0 ^ 1 = 1//1 ^ 1 = 0
Flip the input bit:
//-1 = 0//-0 = 1
Shift left the binary digits by n, pad 0’s on the right
//00010110 << 3//= 10110000
Shift right the binary digits by n, pad 0’s on the left
//00010110 >> 3//= 00000010
get_bit(x, position) = (x >> position) & 1//position is counted from right to left, start from 0.position = 6, x = 01100110get_bit(x, 6) = 1get_bit(x, position) = (01100110>>6) & 1 = (00000001) & (00000001) = 1
set_bit(x, position):mask = (1<<position)return (x | mask)//position = 5//x = 00010110//mask = 0010000//res = 00110110
flip_bit(x, position):mask = (1<<position)return x ^ mask
Quick Links
Legal Stuff
Social Media