delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/12/10:17:45

Sender: "Rolf Campbell" <cp1v45 AT nortelnetworks DOT com>
Message-ID: <3789F891.E01D4486@americasm01.nt.com>
Date: Mon, 12 Jul 1999 10:15:46 -0400
From: "Rolf Campbell" <cp1v45 AT nortelnetworks DOT com>
Organization: Nortel Networks
X-Mailer: Mozilla 4.6 [en] (X11; I; HP-UX B.10.20 9000/712)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com
Subject: Re: bits and flags
References: <01beca3f$da040700$LocalHost AT thendren> <3787DE6D DOT BACB1B58 AT silesia DOT top DOT pl>
X-Orig: <cp1v45 AT americasm01 DOT nt DOT com>
Reply-To: djgpp AT delorie DOT com

Michal wrote:

> > >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.
> >
> > or, if you like assembler you can use "setb" and friends.
> > in addition, OR'ing allows you to set a bit, and you can also AND a bit out
> > with a mask.  using logical bitwise operations are usually faster than
> > adding and subtracting.
> Not true, i don't know about other processors but pentium and higher
> (which is the platform of djgpp) execute them all at the same speed,
> which is in perfect conditions two instructions per clock on pentium and
> pentium MMX and two or one (depending on operands types) instruction for
> pentium pro and pentium II, also in both you can use registers or
> immediate so there are no speed differences.

    But, it is much safer to use the bit-wise logical operators.  Adding 16 to a
number with the 5th bit already set will mess things up.

--
     -Rolf Campbell (39)3-6318



- Raw text -


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