Solved

# Duplicating binary data in array

Posted on 2006-10-21

Hi,

I have an array of unsigned longs called "lookup". I need to copy a bit from one part of the "marix" to another.

i.e. at the jth bit from the right in row[i] should equal the xth bit from the right in row[y].

I'm trying to do this with bitwise operators. I've come up with somthing like:

lookup[i] |= (lookup[y] & (1L << x)) >> (j-31)

(Don't worry, there arn't any magic numbers in the actual program!)

For instance, when i = 2, j=29, y=1, x=30:

Start:

lookup[0] = 0 0 0 0 0 0 0 0 0 ... 0

lookup[1] = 0 1 0 0 0 0 0 0 0 ... 0

lookup[2] = 0 0 0 0 0 0 0 0 0 ... 0

Should finish up like:

lookup[0] = 0 0 0 0 0 0 0 0 0 ... 0

lookup[1] = 0 1 0 0 0 0 0 0 0 ... 0

lookup[2] = 0 0 1 0 0 0 0 0 0 ... 0

Any help would be really appreciated.

Chris