BozonHE wrote:

> Hello. I have following question, can someone explain to me, how I can

> shift left some value using only pen and paper? Or is there some clever

> way without playing with binary numbers at all?

>

>

> "After execution of the final assignment to ByteVal, what will be the

> numeric value of X?

>

> void main()

> {

> unsigned char X=7;

> X <<= 4;

> }

>

> A) 28

> B) 11

> C) 112

> D) 56

> "
This reminds me of the old joke: "There are 10 types of people - those

who understand binary and those who don't."

That being said, here are

some base-neutral hints.

A number a_n ... a_1 a_0 in base b actually means:

\sum_{i=0}^n a_i b^i

Thus the decimal number 234 means:

2*(10^2) + 3*(10^1) + 4*(10^0)

Shifting a_n ... a_1 a_0 left by 1 yields:

a_n ... a_1 a_0 0

Or (if you prefer), a'_{n+1} a'_n ... a'_1 a'_0, where:

a'_{i+1} = a_i (for i >= 0)

a'_0 = 0

Thus, shifting 234 left by 1 in decimal yields:

2*(10^3) + 3*(10^2) + 4*(10^1) + 0*(10^0) = 2340

This is 10 times the original number. I wonder what would happen if you

did the same exercise in binary...?

Regards,

Stu