Coder's Guild Mailing List

Re: Binary Operations

Posted by Weasel on 1999-05-01

Frank Hale wrote:
> 
> Okay say I have a byte
> 
> /* Bit No. 7   6   5   4   3   2   1   0
>            S   V       B   D   I   Z   C */
> byte flags;
> 
> I want to set individual bits in the byte. How would I go about setting
> them in C?

var = var | (1 << BitNr)

-- 
Weasel                          mailto:palfrader@xxxxxxx.xxx
Peter                   http://www.cosy.sbg.ac.at/~ppalfrad/
------------------------------------------------------------
     We have full klingon console support just in case.
                         -- Alan Cox on linux-kernel