Mail Archives: djgpp/1999/07/08/17:17:52
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 -