Blitz (418/459)

From:Damir Arh
Date:26 Jan 2000 at 21:10:16
Subject:Re: Complementing Bits

Hello

> This is a simple problem really, the thing is that I need to 'reverse' a
> number, in this I mean that 0 becomes 7, 1 becomes 6, 2 becomes 5 etc.
Now
> I understand that I need to 'complement' this number, however since I am
> only using 3 BITs, i have 5 spare BITs which will always be reverted to
'1'
> or on, therefore having too much, I can stop this with by minussing 248
from
> the result.

> Say we have the number 5; that would be %00000101 when stored in a byte;
in
> order to complement it, the result should be:-

> %11111010

> Then I minus 248 to give: %00000010, ie: 2. Now here's the thing, in
order
> to complement value do I used AND or OR (or even XOR?)?? I thought ROXL
(is
> that the one?), but I think all I need is the use of AND or OR. Is the
> following method correct:

> #REMOVE_VALUE=248
> byte.b=%00000101 ; 5
>
> byte.b=byte OR %11111111 ; could be AND, but unlikely...
> byte-#REMOVE_VALUE

> Does this give the correct results?

Nope, you'll always gut only 1s at the last three places.

You should use:

#MASK=%00000111
byte.b=%00000101 ; 5

byte.b = byte XOR #MASK ; 2

I guess this should do what you want.

Kind regards

Damir Arh <damir.arh@telesat.si>
http://damir.gajba.net/



Student | Programmer | Translator | Webmaster

---------------------------------------------------------------------
To unsubscribe, e-mail: blitz-list-unsubscribe@netsoc.ucd.ie
For additional commands, e-mail: blitz-list-help@netsoc.ucd.ie