[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] bitskifte !



On Wed, 1 Sep 1999, Joachim Holst wrote:

> Detta stämmer väl fullt ut, men när har man nytta utav den ??
> Hade varit bra med ett exempel på detta med. Finns visst inte mycket i
> böckerna... :-(

Tjoh, hvis du har nogle bits:

#define OPEN (1 << 0)
#define LOCKED (1 << 1)
#define TRAPPED (1 << 2)

int status = OPEN|LOCKED|TRAPPED;


Og nu vil du fjerne OPEN bitten fra ovenstående så skriver du:

status = status & (~OPEN)

Altså AND'er du med en bitmaske som har alle bit sat udover OPEN bitten.
Og siden 0 eller 1 AND 0 eller 0, så bliver den bit clearet.


-- 
==============================================================================
Erwin Andreasen   Herlev, Denmark <sslug@sslug>          UNIX System Programmer
<URL:http://www.andreasen.org>              <*>         (not speaking for) DDE
==============================================================================



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *