Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A sequence of bitwise of operation on bits grouped two by two

I am looking for a sequence of bitwise operations that has the following property:

   | 00  01  10  11
---|---------------
00 | 00
01 | 01  01
10 | 00  01  00
11 | 00  01  11  11

The groups of bits operated upon are on the vertical and horizontal margins, the result matrix is symmetrical.

like image 667
qed Avatar asked Jan 25 '26 17:01

qed


1 Answers

The following code implements what you would like in C/C++.

#include<stdio.h>
int main(void)
{
    int i, j;
    for(i=0; i<4; i++)
    {
        for(j=0; j<4; j++)
        {
            int x = i&j&(i|j)<<1|(i|j)&(~((i^j)&(i^j)>>1)|(i>>1^i))&1;
            printf("%d%d ", x>>1, x&1);
        }
        printf("\n");
    }
    return 0;
}
like image 54
ACcreator Avatar answered Jan 29 '26 09:01

ACcreator