-
Shifted bits
:confused: I am using 4-byte integers to perform various logical
functions and what I want to be able to do is save any overflow or shifted right or left bits after I have peformed a particular function eg
F = (H'12345678 << 23);
F would then equal H'9E000000
How can I save the shifted (lost) bits efficiently for manipulation later on.
This must be easy I know...but I cannot see it
Thanks - Ragnam
-
Shift it the opposite direction first, then back. Place that value in a seperate variable. Consider:
10101101
We want a 3 shift left. Shift right 5 first:
00000101
Shift it back.
10100000
Store that in a variable. Use N-X bytes, where N is the number of bytes in the variable, and X is the number you're shifting, to get your value of how far to shift in the opposite direction and back.
Quzah.
-
Thanks for that Quzah.
Can this method be used to also test for a carry-bit when
two numbers are added together ?
eg H'EA000000 +
H'D6000000
---------------
H'1 C0000000
Using a 4-byte integer would normally lose the carry '1'
Ragnam
-
Why do you keep using an H and an apostrophe in your numbers? What is that supposed to denote? That is nothing in C.
Quzah.
-
It was for demonstration only, that the values were hex....sorry.
F = (0xEA000000 + 0xD6000000)
F = 0xC0000000
Using a 4-byte integer would normally lose the carry '1'
Ragnam