It doesn't look correct to me.
Take, for instance your
msb
function (I didn't scrutinize the other ones), it takes
value
and stores it in the second byte of
value16
on a little endian machine.
The following program
#include <arpa/inet.h>
using namespace std;
void show(uint16_t u16)
{
uint8_t * p = reinterpret_cast< uint8_t * > ( & u16 );
cout << hex << p[0] << p[1] << "\n";
}
inline void msb(uint16_t & value16, uint8_t value)
{
value16 = (value16 & 0x7f) | uint16_t((value & 0x7f)<<8);
}
int main()
{
uint16_t bes = htons(0x666F);
show(bes);
uint16_t beh = 0x6F6F;
msb(beh, 0x66);
show(beh);
}
outputs
fo
of
on my little endian Linux box