www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/03/12:09:39

Date: Wed, 3 Feb 1999 19:03:30 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: anarko <anarko AT flashback DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: what is wrong with this?
In-Reply-To: <15708.990203@flashback.net>
Message-ID: <Pine.SUN.3.91.990203185620.21364D-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019