I want to know when I do 4<<2, what exactly happens underneath?? are there any multiplications performed or how is the value computed. if you have a reference to the implementation of shift operators please reply me. Thanks in advance
+3
A:
In your particular case the compiler will shortcut it to the constant, but in general instruction set of processors includes special opcodes (operation codes, commands) to perform bit shift operations.
Here's good explanation of how this works.
Eugene Mayevski 'EldoS Corp
2010-09-29 16:21:21
Yep.. thanks eugene
reddy
2010-09-29 16:27:55
+1
A:
In hardware terms, each output bit is generated by selecting one of the input bits. No multipliers required, just a lot of multiplexing.
Oli Charlesworth
2010-09-29 16:22:33
+4
A:
Normally this is a processor instruction (directly done on the processor).
It simply does shift the bits in memory:
int a = 3; // a = 0 0 1 1
a << 1; // a = 0 1 1 0 = 6
a << 1; // a = 1 1 0 0 = 12
If you are looking for insight on how processors work in a very low level, Code by Charles Petzold is a fantastic book to read.
Oded
2010-09-29 16:23:52
A:
supercat
2010-09-29 17:45:09