Hi ! I am trying to figure out how exactly arithmetic bit-shift operators work in C, and how it will effect signed 32 bit integer.
To make things simple, lets say we work within one byte(8 bits) -
x = 1101.0101
MSB[ 1101.0101 ]LSB
Reading other posts on Stack & some websites, I found that: << will shit toward MSB(to the left, in my case ), and fill "empty" LSB bits with 0s
and >> will shift toward LSB (to the right, in my case), and fill "empty" bits with MS bit
so, x = x << 7
will result in moving LSB to MSB, and setting everything to 0s
1000.0000
Now, lest say I would >> 7, last result
This would result in [0000.0010]
? I am right ???
Thanks ! (Please, check if I was right about my assumptions about shift operators)
Edit: I just test on my machine,
int x = 1; //000000000......01
x = x << 31; //100000000......00
x = x >> 31; //111111111......11 (everything is filled with 1s !!!!!) - Why ????