Bitwise Operators

Here are bitwise operators that I use, along with sample input and output in base-10, base-2, and base-16.

To generate this table I used a script similar to this, where I would substitute the respective expression for exp.

a = 17, b = 29;
exp = '+';
eval('x = a ' + exp + ' b;');
function format(base) {
return 'Base ' + base + ': ' + a.toString(base)
+ ' ' + exp + ' ' + b.toString(base)
+ ' = ' + x.toString(base);
}
b10 = format(10), b2 = format(2), b16 = format(16);
alert(b10 + '\n' + b2 + '\n' + b16);
Expression base-10 base-2 base-16
Bitwise XOR 17 ^ 29 = 12
  10001
^ 11101
= 01100
11 ^ 1d = c
Bitwise AND 18 & 29 = 16
  10010
& 11101
= 10000
12 & 1d = 10
Bitwise OR 18 | 25 = 27
  10010
| 11001
= 11011
12 | 19 = 1b
Left shift 3 << 2 = 12 11 << 10 = 1100 3 << 2 = c
Right shift 56 >> 3 = 7 111000 >> 11 = 111 38 >> 3 = 7
Bitwise complement ~43 = -44 ~101011 = -101100 ~2b = -2c