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:
Code:
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:
Code:
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:
Code:
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