Switches a 16/32-bit value between big/little endian.
Language:
Dark Basic Pro
Code:
function ChangeEndian(value as integer) result = ((value && 0xFF) << 24) || ((value && 0xFF00) << 8) || ((value && 0xFF0000) >> 8) || ((value && 0xFF000000) >> 24) endfunction result
(1 vote)
Wed, 11/28/2007 - 10:14
In what scenario would you use this?
Wed, 11/28/2007 - 16:55
In the scenario that you would want to convert from little endian to big endian and vice versa.
Certain standard file formats (such as PNG), store values in big endian (PNG uses the network byte order which just so happens to be big endian). If you read these values you'll need to convert them to little endian to do anything useful with them.