Sender: nate AT cartsys DOT com Message-ID: <36B8BF51.B6DC9E1B@cartsys.com> Date: Wed, 03 Feb 1999 13:27:45 -0800 From: Nate Eldredge X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.0.36 i586) MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: what is wrong with this? References: <15708 DOT 990203 AT flashback DOT net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com anarko wrote: > > Hello everybody, i have a little problem, > i wrote a little routine that resets a specific > bit in a char, and it worked fine. then i just wanted > to reduce the lines of code it was written in > to one line or something and it doesnt work correct, > > i reduced it to: > bittmp = tmp << 2; > bittmp = ((tmp >> 7) << 7) | (bittmp >> 2); > > without problems, but when i wrote it to: > bittmp = ((tmp >> 7) << 7) | ((tmp << 2) >> 2); ^^^^^^^^^^ Although your variables are unsigned char, intermediate calculations are still done as `int', as the language requires. Thus, in `tmp << 2', the high bits are not shifted off the end, and come right back when you right-shift. Either insert a cast to `unsigned char' (ugly), or mask this result with 0xff (better). -- Nate Eldredge nate AT cartsys DOT com