I've read in 4 bytes binary string from a file. The 4 bytes binary string is big endian, and represents a 32-bit integer. But My machine is little endian (intel). So I need to convert the 4 bytes binary string of big endian into 32-bit little endian integer.
Is there any native function in mysql could handle this? An example will be highly appreciated.
Thanks.
Update: OS dependent function or c/c++ standard library is highly restricted in mysql project and could hardly be used in this case.
For C you can use ntohl()
to convert 32bit (that is 4 bytes) integers to host byte order.
Its prototype should reside in <arpa/inet.h>
.
Update
The ntoh/hton
family of functions is defined by the POSIX standard.
It converts network byte order to host bytes order and verse visa.
Network byte order is defined to be Big Endian.