Posted on 1999-01-12
I need to write a function that, given a byte, will return the byte with bits in reverse order. For example, if it is given
the return value would be
Is there a better way to do this than checking bits in a loop and shifting the source byte and the target byte ?
I know this sounds like homework, but it isn't. The reason I need to do this is that I want to read data from a device through LPT. I have a function that reads a word, but, inside that word, one byte is reversed. I need to un-reverse it QUICKLY, and the shifting loop takes too much time.
I realize that I can do this faster in Assembly using the carry register, but I was looking for a way to do this in plain C, with & | ~ ^ and so on.