Joseph Haugh
University of New Mexico
0xFA1D37B
or0xfa1d37b
0x39A7F8
to binary:Convert 0x39A7F8
to binary:
3 | 9 | A | 7 | F | 8 |
---|---|---|---|---|---|
0011 | 1001 | 1010 | 0111 | 1111 | 1000 |
Convert 1100100101111011
to hexadecimal:
Convert 0x39A7F8
to binary:
3 | 9 | A | 7 | F | 8 |
---|---|---|---|---|---|
0011 | 1001 | 1010 | 0111 | 1111 | 1000 |
Convert 1100100101111011
to hexadecimal:
1100 | 1001 | 0111 | 1011 |
---|---|---|---|
C | 9 | 7 | B |
1
, False = 0
.AND
(A & B = 1
if both A = 1
and B = 1
).OR
(A | B = 1
if either A = 1
or B = 1
).NOT
(~A = 1
if A = 0
).XOR
(A ^ B = 1
if either A = 1
or B = 1
, but not both).Operators apply bitwise:
01101001 & 01010101 = 01000001
01101001 | 01010101 = 01111101
01101001 ^ 01010101 = 00111100
~01010101 = 10101010
All of the properties of boolean algebra apply (p. 52)
^
, &
, ~
) on bit vectors form Boolean rings.bit vector of length w, used to represent subsets of {0, …, w–1}
aj = 1 if j ∈ A
{ 0, 3, 5, 6 }
0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 |
---|---|---|---|---|---|---|---|
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
{ 0, 2, 4, 6 }
0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
---|---|---|---|---|---|---|---|
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
01101001 { 0, 3, 5, 6 }
01010101 { 0, 2, 4, 6 }
set operations performed as logical operations over bits
op | name | result |
---|---|---|
& | Intersection | 01000001 { 0, 6 } |
| | Union | 01111101 { 0, 2, 3, 4, 5, 6 } |
^ | exclusive or | 00111100 { 2, 3, 4, 5 } |
~ | Complement(of 2nd) | 10101010 { 1, 3, 5, 7 } |
x << y
):
x
left by y
positions.x >> y
):
Argument x | 01100010 |
---|---|
<< 3 | 00010000 |
Log. >> 2 | 00011000 |
Arith. >> 2 | 00011000 |
Argument x | 10100010 |
---|---|
<< 3 | 00010000 |
Log. >> 2 | 00101000 |
Arith. >> 2 | 11101000 |