J
Jeremy Targett
Hello, I've been using a routine that reflects the bits in a field of
length 12, keeping the lowest one in place. So this ordering of bits:
12 11 10 9 8 7 6 5 4 3 2 1
gets mapped into this ordering:
2 3 4 5 6 7 8 9 10 11 12 1
What I'd like to do instead is to get the circular rotation of the
reflection that exchanges the position of the highest and lowest bits
that happen to be set. For example,
000100110011 ==> 000110011001
Could anyone suggest how to modify my code so it accomplishes this? Many
thanks --Jeremy
#define MASK 07777
#define OVER 010000
reflect(unsigned x)
{
unsigned t;
int i;
t = 0;
for (i = 0; i < 12; i++)
{
t |= (x & 001);
x >>= 1;
t = rotate(t);
}
return t;
}
rotate(unsigned x)
{
x <<= 1;
if (x & OVER)
x |= 001;
return(x & MASK);
}
length 12, keeping the lowest one in place. So this ordering of bits:
12 11 10 9 8 7 6 5 4 3 2 1
gets mapped into this ordering:
2 3 4 5 6 7 8 9 10 11 12 1
What I'd like to do instead is to get the circular rotation of the
reflection that exchanges the position of the highest and lowest bits
that happen to be set. For example,
000100110011 ==> 000110011001
Could anyone suggest how to modify my code so it accomplishes this? Many
thanks --Jeremy
#define MASK 07777
#define OVER 010000
reflect(unsigned x)
{
unsigned t;
int i;
t = 0;
for (i = 0; i < 12; i++)
{
t |= (x & 001);
x >>= 1;
t = rotate(t);
}
return t;
}
rotate(unsigned x)
{
x <<= 1;
if (x & OVER)
x |= 001;
return(x & MASK);
}