What is the quickest way to reverse the endianness of a 16 bit and 32 bit integer. I usually do something like (this coding was done in Visual Studio in C++):
un
At least in Visual C++, you can use _byteswap_ulong() and friends: http://msdn.microsoft.com/en-us/library/a3140177.aspx
These functions are treated as intrinsics by the VC++ compiler, and will result in generated code that takes advantage of hardware support when available. With VC++ 10.0 SP1, I see the following generated code for x86:
return _byteswap_ulong(val);
mov eax, DWORD PTR _val$[esp-4]
bswap eax
ret 0
return _byteswap_ushort(val);
mov ax, WORD PTR _val$[esp-4]
mov ch, al
mov cl, ah
mov ax, cx
ret 0