Logical shift and arithematic shift

Status
Not open for further replies.

sunidrak

Full Member level 1
Joined
Apr 12, 2012
Messages
97
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Bengaluru, India
Activity points
1,738
If we do 1bit logical left shift in a 8 bit register then the

new value=2 times the old value
suppose the Old value is 10000010 (130 in decimal)
then the New value 00000100 (4 in decimal)
then the statement left shift will produce 2 times the old value will not be true

can anybody plz explain how it hold true ??
If we do 2bit left shift then the new value will be 4 times the old one ?? Wat is relation ??
 

The statement holds true as long as you don't exceed the given bit length max value (255 for 8 bit), if you exceed it then you get a truncated result , the same as if you try to do it using

Code:
uin8_byte = 130 * 2;

If you try it with a 16bit data type then it will work fine in both cases.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…