[futurebasic] Re: [FB] Bit swapping

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 1999 : Group Archive : Group : All Groups

From: Paul Bruneau <paul_bruneau@...>
Date: Wed, 20 Oct 1999 13:33:39 -0400
You're right. My brain is broken. Ignore my XOR post.

Sorry,

PB

Zetalink Technology wrote:
> 
> __level-1 text from Hans van Maanen. T = 20.10.99|16:19 +0200 __
> 
> >What would be the fastest way to swap eight bits, so that e.g. 64 becomes 2
> >(01000000 <> 00000010) and 192 becomes 3 (11000000 <> 00000011)?
> >
> >Can this be done without a loop FOR i = 0 to 3 et cetera?
> >
> 
> To clarify, I believe what you what you want is hgfedcba to become
> abcdefgh, where each bit's symbolic letter contains the same bit
> value.
> 
> One possibility, a string of eight IF-THENs:
> 
> IF &80 AND old THEN new = 1
> IF &40 AND old THEN new = new + 2
> IF &20 AND old THEN new = new + 4
> IF &10 AND old THEN new = new + 8
> IF 8 AND old THEN new = new + &10
> IF 4 AND old THEN new = new + &20
> IF 2 AND old THEN new = new + &40
> IF 1 AND old THEN new = new + &80
> 
> Another, in a single expression
> :
> new = (&80 AND old) >> 7 + (&40 AND old) >> 5 + (&20 AND old) >> 3
>      + (&10 AND old) >> 1 + (  8 AND old) << 1 + (  4 AND old) << 3
>      + (  2 AND old) << 5 + (  1 AND old) << 7
> 
> ( I am not positive if there needs to me more parentheses in there so
> that the sub-expression following the shift is not added to the shift
> )
> 
> Ray Weisling
> Yogyakarta
> 
> Zetalink Technology Indonesia, Ltd.
> 
> --
> To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>