Thursday, December 01, 2005

How will get 0x12 from 0x1234?

Just do Right Shift 8 times. Thats it.

But Normally we say that & with 0xFF00 and do right shift 8 times. Please remember to think before answering what is the question and the possibilities to reduce instructions/ execution time/ memory consumptioin.

Simple Example, If we want to multiply a value by 2, we put

"value * 2"

But efficient way would be

"Value << 1"

That is left shift one time will give multiples of two. This will reduce the CPU cycles consumed.

Left Shift is faster than Multiplication

1 comment:

Anonymous said...

Good explanation. good work mappu.