delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/08/17:17:52

From: varobert AT colba DOT net
Message-Id: <3.0.32.19990708171722.007a2820@mail.colba.net>
X-Sender: varobert AT mail DOT colba DOT net
X-Mailer: Windows Eudora Pro Version 3.0 (32)
Date: Thu, 08 Jul 1999 17:17:31 -0400
To: djgpp AT delorie DOT com
Subject: Re: bits and flags
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

To set a bit, simply or it:
ex: ch|=1; will set the first bit.
To turn off a bit, you need to xor it if it's set.
if (ch&1) ch^=1;
or you can and the "opposite" (all bits set except the one you want to unset)
ch&=0xFFFFFFFE;
or ch&=(1^0xFFFFFFFF);

- GodOfWar

At 06:39 PM 7/8/99 +0200, you wrote:
>Lets say I have
>char ch=1;
>
>Now I can test if a bit is "on"
>if(ch&1)
>  .......
>
>but how can I set a bit.. Lets say bit 4?
>and how can I "turn off" a bit?
>
>hope you understand my question...
>thanx
>
>
>
>

- Raw text -


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