Society of Robots - Robot Forum
Software => Software => Topic started by: Razor Concepts on July 01, 2010, 08:41:45 AM
-
Original operation:
((0xFF0000 >> 16) >> 3) << 11
It is NOT equivalent to:
0xFF0000 >> 8
It is equivalent to, and the most simplified operation is:
(0xFF0000 >> 19) << 11
Is this all correct? Just making sure.
-
Sounds right.
To check do each shift operation independently and look at the result in your debugger/simulator or on paper.
My best explanation is that once a bit is shifted out of the word (24 bits) the bit is sent to the bit-bucket. When a bit is shifted in from the other end it is a zero shifted in. So breaking the operations down:
0xff0000 >> 16 = 0x0000ff
0x0000ff >> 3 = 0x00001f
0x00001f << 11 = 0x00f800
Whereas:
0xff0000 >> 8 = 0x00ff00
and:
0xff0000 >> 19 = 0x00001f
0x00001f << 11 = 0x00f800
Another way to get this result is:
(0xff0000 >> 8) & 0x00f800
if the 5 bits you need are not always ones
-
Thanks!
by the way, what would the "<<=" operator mean?
Like num<<=1 ?
-
num<<=1
I wasn't sure so I put that in some code and ran it under the simulator.
It takes the value in num, shifts it left one bit then assigns it back to num. Which makes perfect sense.
If num = 0x05
then do
num<<=1
num is now 0x0A
Does your C compiler have a debugger/Simulator? Its very handy the test what stuf like that does.
Or are you just testing me? lol
-
Thanks! my compiler does have a debugger but I just got started using it and MSP430s a few days ago so I am still fairly lost :D
with so many different commands that can be used... maybe the creators of C put in a special one that unlocked the secrets of the universe :-X
-
by the way, what would the "<<=" operator mean?
Like num<<=1 ?
Its the same as: num = num<<1
In C you often see operators on the left of the equals ie
num *= 10 is the same as num = num *10
num += 10 is the same as num = num + 10
num -= 10 is the same as num = num - 10
etc
-
maybe the creators of C put in a special one that unlocked the secrets of the universe :-X
They did, it's 0x000015 <<=
;D