Archive: Bitwise operations...without bitwise operators


27th May 2003 01:01 UTC

Bitwise operations...without bitwise operators
In somewhat of a continuation of this thread, I'd like to know if anyone out there knows how to (or could figure out how to) do bitwise operations without the beloved b0rk3n | and & operators.

Don't ask me why I want to use them...it's a secret :D


27th May 2003 01:23 UTC

you mean this sort of thing

for &
a=if(condition1,(if(condition2,1,0),0);

for |
a=if(condition1,1,if(condition2,1,0));

I might have missed the point though


27th May 2003 01:29 UTC

umm, no. that generates the right truth table, but try doing that with 64 variables at a time. not only is it a pain in the ass, it's literally impossible to do.


27th May 2003 01:34 UTC

ah... it sounds like what you need to do would be very hard without loop structures.
why cant you just use the real operators, or will that ruin the secret.


27th May 2003 02:28 UTC

Because you haven't read the original thread...


27th May 2003 03:01 UTC

*cough cough* dumbass *cough*

and dare i mention...

... the beloved b0rk3n | and & operators.
:rolleyes:


<edit> just now found a way to read single bits out of a variable. i set up a scope to demonstrate it:
init: n=16
beat: bits=pow(2,rand(16))+pow(2,rand(16))+pow(2,rand(16));
frame: p=0;
pixel:
x=i-0.5; y=0;
red=(bits%pow(2,p)-bits%pow(2,p-1))+0.4; blue=red; green=red;
p=p+1;

gray bits (points) are off, white ones are on.
(now, getting exactly 3 bits to turn on every time will be a problem...but then again, it would be with the operators working properly as well :weird: )

the same operation can be used to toggle a bit, or turn it on or off. the following three lines of code toggle a bit, turn a bit on, and turn a bit off, respectively:
variable=if(variable%pow(2,bit)-variable%pow(2,bit-1),variable-pow(2,bit),variable+pow(2,bit));
variable=if(variable%pow(2,bit)-variable%pow(2,bit-1),variable,variable+pow(2,bit));
variable=if(variable%pow(2,bit)-variable%pow(2,bit-1),variable-pow(2,bit),variable));

27th May 2003 03:07 UTC

tut tut.

im sorry.. i assumed that it was talking about a different thread that i had already read. whooooooops, dont i feel like the right ass.
also i couldnt work out what b0rk3n (br0k3n) meant....

well. .i have no freeken idea then


27th May 2003 12:09 UTC

Well i already had made up something a bit like that, but long ago.

To tear your var appart, starting with the biggest possible pow of 2.
If you can substract it, then do and remember this pow of 2 is 1. Then go down to the next pow. If you once can't substract it its 0. This way you should be able to get a virtual long bitstring.

However, this would result again in tons of vars unless you do a routine that uses only one buffer to compare the stuff und write the new bit.

Don't take it as a clear instruction but this way it should be possible through a painfull process.