Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!

# Mock exam Q

yun jiang
Greenhorn
Posts: 3
Can anyone tell me why the ouput of 0X81>>2 is 0X20?
thanks.

Marilyn de Queiroz
Sheriff
Posts: 9068
12
Originally posted by yun jiang:
Can anyone tell me why the ouput of 0X81>>2 is 0X20?
thanks.

0000 0000 0000 0000 0000 0000 1000 0001 = 0X81
move everything two slots to the right and you get
0000 0000 0000 0000 0000 0000 0010 0000 = 0X20

Have you seen the campfire story "Cat and Mouse Games with Bits"?

Lawrence Thurman
Greenhorn
Posts: 3
0x81 >> 2 = 0x20
First you need to convert the hex to a decimal number
hex 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
dec 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
hex 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
dec 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
so if 0x00 hex = 00 dec
0x10 hex = 16 dec
0x20 hex = 32 dec
0x30 hex = 48 dec
0x40 hex = 64 dec
0x50 hex = 80 dec
0x60 hex = 96 dec
0x70 hex = 112 dec
0x80 hex = 128 dec
I think that should give you the pattern basically think in 16s instead of 10s ...
10 20 30 40 50 60...
16 32 48 64 80 96...
or you can take the simple way
first number * 16 + the second number
8 * 16 = 128 + 1 = 129
now you can take this into a binary format
Binary increments like memory double the last number
1 2 4 8 16 32 64 128 256 512 ....
they are represented from right to left
for our case
1
2 6 3 1
8 4 2 6 8 4 2 1
129 = 1 0 0 0 0 0 0 1
now use the >> 2
and get
1
2 6 3 1
8 4 2 6 8 4 2 1
0 0 1 0 0 0 0 0
32 decimal
convert back to hex
look at the chart 32 = 0x20