delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/08/14:31:55

From: Darren Noble <darren AT calderathin DOT com>
To: djgpp AT delorie DOT com
Subject: Re: bits and flags
Date: Thu, 8 Jul 1999 12:29:58 -0600
X-Mailer: KMail [version 1.0.17]
References: <3784d701 AT 193 DOT 13 DOT 199 DOT 3>
MIME-Version: 1.0
Message-Id: <99070812341600.00695@dome.calderathin.com>
Reply-To: djgpp AT delorie DOT com

On Thu, 08 Jul 1999, 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?

If you take 2 to the 4th power witch is 16, you can say:

	ch-=16;

and that will turn of the 4th bit if it is on.  If it is off and you want it on
you can go

	ch+=16;

so basicly you add or subtract 2 to the power of the bit you want.

> 
> hope you understand my question...
> thanx

- Raw text -


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