Mail Archives: djgpp/1999/02/03/12:09:39
On Wed, 3 Feb 1999, anarko wrote:
> bittmp = tmp << 2;
> bittmp = ((tmp >> 7) << 7) | (bittmp >> 2);
>
> without problems, but when i wrote it to:
> bittmp = ((tmp >> 7) << 7) | ((tmp << 2) >> 2);
>
> it did no longer work (it returned 11111111 binary, as i inputted in
> it)
You forget that C promotes all integral data types to int's in an
expression. In other words, ((tmp << 2) >> 2) is a no-op, since tmp is
loaded into a 32-bit register, where the high two bits aren't shifted out
by the innermost parentheses. In the first example, the 2 high bits are
chopped off when you store the result of (tmp << 2) into an 8-bit
variable.
Btw, to reset bit 6, which is what you seem to want, you don't need to go
to such great lengths. All you need is this:
bittmp = tmp & 0xCF;
- Raw text -