|
|
|
|
|
|
|
|
|
|
|
|
Bitshift operators |
|
|
|
|
x << n |
Shift bits of x left by n
digits |
|
|
|
|
Insert 0's on the right |
|
|
|
|
|
|
x >> n |
Shift bits of x right by
n digits |
|
|
|
|
If unsigned or
non-negative, insert 0's on left |
|
|
|
If signed, may be system
dependent |
|
|
|
|
|
|
Important: x DOES NOT
CHANGE! |
|
|
|
|
(just like x + 2 does not
change x) |
|
|
|
|
x <<= n
|
|
change x |
|
|
|
|
x >>= n |
|
|
|
x and n must be int |
|
|
|
|
|
|
Examples: |
|
|
|
|
int x = 5; |
|
|
|
|
x |
0000 |
0000 |
0000 |
0000 |
0000 |
0000 |
0000 |
0101 |
|
|
x << 3 |
0000 |
0000 |
0000 |
0000 |
0000 |
0000 |
0010 |
1000 |
|
x >> 2 |
0000 |
0000 |
0000 |
0000 |
0000 |
0000 |
0000 |
0001 |
|
|
|
|
|
|
|
|
What arithmetic
operations do these correspond to? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|