www.digitalmars.com         C & C++   DMDScript  

D - XOR Bit Array

reply resistor mac.com writes:
Hey folks!

I have a question about something i'm trying to write in D.  I have two arrays
of 144 bits, and I 
need to XOR them, and store the result in yet a third array of 144 bits.  Any
suggestions on how to 
do this?  Do the bit arrays need to be dynamic or static?  I'm just a tad
confused!

Thanks,
Owen Anderson
Sep 16 2003
parent reply John Boucher <John_member pathlink.com> writes:
In article <bk7u0c$1tb9$1 digitaldaemon.com>, resistor mac.com says...
Hey folks!

I have a question about something i'm trying to write in D.  I have two arrays
of 144 bits, and I 
need to XOR them, and store the result in yet a third array of 144 bits.  Any
suggestions on how to 
do this?  Do the bit arrays need to be dynamic or static?  I'm just a tad
confused!

Thanks,
Owen Anderson
Uhhh... Use != to xor bits, and use a for statement to walk the array? John Boucher The King had Humpty pushed
Sep 16 2003
parent reply resistor mac.com writes:
In article <bk7vhl$23mn$1 digitaldaemon.com>, John Boucher says...
In article <bk7u0c$1tb9$1 digitaldaemon.com>, resistor mac.com says...
Hey folks!

I have a question about something i'm trying to write in D.  I have two arrays
of 144 bits, and I 
need to XOR them, and store the result in yet a third array of 144 bits.  Any
suggestions on how to 
do this?  Do the bit arrays need to be dynamic or static?  I'm just a tad
confused!

Thanks,
Owen Anderson
Uhhh... Use != to xor bits, and use a for statement to walk the array? John Boucher The King had Humpty pushed
Is it not possible to use an array operator to do all of them at once? And also, isn't ^ the XOR operator? That's what the documentation says, but I suppose it could be wrong. Owen Anderson
Sep 16 2003
parent reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
<resistor mac.com> wrote in message news:bk81nb$2bh3$1 digitaldaemon.com...
 In article <bk7vhl$23mn$1 digitaldaemon.com>, John Boucher says...
In article <bk7u0c$1tb9$1 digitaldaemon.com>, resistor mac.com says...
Hey folks!

I have a question about something i'm trying to write in D.  I have two
arrays
of 144 bits, and I
need to XOR them, and store the result in yet a third array of 144 bits.
Any
suggestions on how to
do this?  Do the bit arrays need to be dynamic or static?  I'm just a
tad
confused!

Thanks,
Owen Anderson
Uhhh... Use != to xor bits, and use a for statement to walk the array? John Boucher The King had Humpty pushed
Is it not possible to use an array operator to do all of them at once?
And
 also, isn't ^ the XOR
 operator?  That's what the documentation says, but I suppose it could be
wrong.
 Owen Anderson
There was a plan once upon a time to implement operations on entire arrays at once, and if that ever gets implemented you'll be able to do something like this: bit[144] a, b, c; a[] = b[] ^ c[]; // could use != instead of ^... ^ returns each bit, != only returns one bit and only acts like an xor if used on single bits Sean
Sep 17 2003
parent reply "Charles Sanders" <sanders-consulting comcast.net> writes:
Isnt there some special CPU instruction set that ill apply an operation to
an array or matrix or something, vectorizing compilers or something like
that ?

Charles

"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:bka32e$2km1$1 digitaldaemon.com...
 <resistor mac.com> wrote in message
news:bk81nb$2bh3$1 digitaldaemon.com...
 In article <bk7vhl$23mn$1 digitaldaemon.com>, John Boucher says...
In article <bk7u0c$1tb9$1 digitaldaemon.com>, resistor mac.com says...
Hey folks!

I have a question about something i'm trying to write in D.  I have
two
 arrays
of 144 bits, and I
need to XOR them, and store the result in yet a third array of 144
bits.
 Any
suggestions on how to
do this?  Do the bit arrays need to be dynamic or static?  I'm just a
tad
confused!

Thanks,
Owen Anderson
Uhhh... Use != to xor bits, and use a for statement to walk the array? John Boucher The King had Humpty pushed
Is it not possible to use an array operator to do all of them at once?
And
 also, isn't ^ the XOR
 operator?  That's what the documentation says, but I suppose it could be
wrong.
 Owen Anderson
There was a plan once upon a time to implement operations on entire arrays at once, and if that ever gets implemented you'll be able to do something like this: bit[144] a, b, c; a[] = b[] ^ c[]; // could use != instead of ^... ^ returns each bit, != only returns one bit and only acts like an xor if used on single bits Sean
Sep 17 2003
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
There certainly is.  It is usually a bit more limited than the normal
instruction set but enough to get most jobs done, with a quickness.  ;)

My coworker just wrote a function for PS2 that processes 16 triangle
bounding boxes at the same time, using a few min/max/compare instructions.

It would be nice if in D you could express this as simply as:

typedef byte[16] b16;
extern b16 a,b,c;
b16 res = a[] + b[] < c[] && a[] - b[] > c[];

Sean

"Charles Sanders" <sanders-consulting comcast.net> wrote in message
news:bkaj99$aq1$1 digitaldaemon.com...
 Isnt there some special CPU instruction set that ill apply an operation to
 an array or matrix or something, vectorizing compilers or something like
 that ?

 Charles

 "Sean L. Palmer" <palmer.sean verizon.net> wrote in message
 news:bka32e$2km1$1 digitaldaemon.com...
 There was a plan once upon a time to implement operations on entire
arrays
 at once, and if that ever gets implemented you'll be able to do
something
 like this:

 bit[144] a, b, c;
 a[] = b[] ^ c[];  // could use != instead of ^... ^ returns each bit, !=
 only returns one bit and only acts like an xor if used on single bits

 Sean
Sep 19 2003