B
benn686
Anyone know of an efficient way of reversing the bits of a word??
Anyone know of an efficient way of reversing the bits of a word??
Nope, where these are available, they reverse the byte order.htons() <-> ntohs()
Not portably, some instructions sets may have a quick way to do this,Anyone know of an efficient way of reversing the bits of a word??
Anyone know of an efficient way of reversing the bits of a word??
Where they are available they convert the native byte order toIan said:Nope, where these are available, they reverse the byte order.
Anyone know of an efficient way of reversing the bits of a word??
Wow! That is slick, and it worked nicely too!
Not quite sure how it works, but for 16 bits, would it work something
like:
n = ((n >> 1) & 0x5555) | ((n << 1) & 0xaaaa) ;
n = ((n >> 2) & 0x3333) | ((n << 2) & 0xcccc) ;
n = ((n >> 4) & 0x0f0f) | ((n << 4) & 0x0f0f) ;
Wow! That is slick, and it worked nicely too!
Not quite sure how it works, but for 16 bits, would it work something
like:
n = ((n >> 1) & 0x5555) | ((n << 1) & 0xaaaa) ;
n = ((n >> 2) & 0x3333) | ((n << 2) & 0xcccc) ;
n = ((n >> 4) & 0x0f0f) | ((n << 4) & 0x0f0f) ;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.