-
shifting? division?
I was hoping someone could maybe write an example to better explain to me this idea. i know its true but I'm having a hard time understanding it,
so its possible to shift a value and by shifting the value its basically like dividing it by a power of 2?? i think or something like that can someone explain by giving an example on how that really works in a C program.
-
consider the following in binary.
0001 = 1 decimal
0010 = 2 decimal
0100 = 4 decimal
1000 = 8 decimal
10000 = 16 decimal
100000 = 32 decimal
see how as the bit shifts to the left the number is multiplied by 2 each move. Division by 2 is just a shift to the right. Also you could read this http://en.wikipedia.org/wiki/Bitwise_operation
-
okay so if its
00101110 and i shift it
>> 3;
wiil that divivde the binary by 8
-
Yep. It will divide the decimal number by 8.