B
brekehan
I am in need of a utility function to change host to network byte
order and back. If I understand things correctly, I just need to make
the most significant bit the least and vice versa or in essence write
the bits backwards.
Its been awhile since I played with bitwise operations. Is there a
better solution, without linking to winsock or a bsd library (just
standard C++), than:
ReverseBitOrder(unsigned long)
{
unsigned long newlong = 0;
// for each bit position in the long
// zero out all other bit's positions
// shift it to 32 - (the bit's position from least significant)
// add it to newlong;
return newlong;
}
Hell, I am not even sure if that is right.
order and back. If I understand things correctly, I just need to make
the most significant bit the least and vice versa or in essence write
the bits backwards.
Its been awhile since I played with bitwise operations. Is there a
better solution, without linking to winsock or a bsd library (just
standard C++), than:
ReverseBitOrder(unsigned long)
{
unsigned long newlong = 0;
// for each bit position in the long
// zero out all other bit's positions
// shift it to 32 - (the bit's position from least significant)
// add it to newlong;
return newlong;
}
Hell, I am not even sure if that is right.