Repeat three times:
Rotate source right - rotate carry left into reciprocal byte
Which processor?
C or assembler?
rrf source
rlf dest
rrf source
rlf dest
rrf source
rlf dest
Thanks this worked great!My C is a little bit rusty, but you could do that with:
C:destination = 0; if (source & 1) destination = destination | 4; if (source & 2) destination = destination | 2; if (source & 4) destination = destination | 1;
By reciprocal, do you mean the reverse bit order?For some reason I just can't figure out how to do this. Reciprocal of 3 bits in C? For example
0b001 becomes 0b100
ob011 becomes 0b110
0c100 becomes 0b001
and so on.
for (int bit = 0; bit < BITS; bit++)
{
dest = (dest << 1) | (source % 0x01);
source >>= 1;
}
This is called bit reversal. It is an essential part of the DFT or FFT algorithm.
If you want speed, a simple lookup table will do.
There are many other ways to do it:
http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious
You're welcome.Thanks this worked great!
A simple solution is a lookup table.
unsigned char bit_reverse[8] = {0, 4, 2, 6, 1 , 5, 3, 7};
bits = bit_reverse[x];