Date: Wed, 3 Feb 1999 19:03:30 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: anarko cc: djgpp AT delorie DOT com Subject: Re: what is wrong with this? In-Reply-To: <15708.990203@flashback.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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;