I have a 64-bit number (but used only 42 least significant bits) and you want to calculate the sum of the bit 4 in the n, n+m, n+m*2and n+m*3(note: anything that can make a sum> 4 is invalid) for some fixed m and each value of n, which puts all bits in a number
as an example, using m=3and considering a 16-bit number
0010 1011 0110 0001
I need to calculate
2, 3, 1, 2, 3, 0, 3
Does anyone have any (cool) ideas on how to do this? I'm fine with a little cool.
My current thought is to make bit shifted copies of the input to align the values ββto be added, and then build a logical tree to make a 4x 1-bit adder.
v1 = In;
v2 = In<<3;
v3 = In<<6;
v4 = In<<9;
a1 = v1 ^ v2;
a2 = v1 & v2;
b1 = v3 ^ v4;
b2 = v3 & v4;
c2 = a1 & b1;
d2 = a2 ^ b2;
o1 = a1 ^ b1;
o2 = c2 ^ d2;
o4 = a2 & b2;
, 3 ints, .
edit: , , - o4, o2&o1, o2 o1 , .
-
arr = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4];
for(int i = 0; i < N; i++)
{
out[i] = arr[(In & 0b1001001001) % 30];
In >>= 1;
}
, , 4 16 ( ) 0-15, mod 30. , 3 4 , .
p.s.
. . , .