SDL Wiki

Byte Order and Byte Swapping

Include File(s): SDL_endian.h


This category contains functions for handling endian-specific values.

Simple data types like integers and floats consist of several bytes. A 32bit integer (Sint32), for example, uses four bytes (as each byte has 8 bits). Endianness describes how the system orders the bytes of this value in memory.

Endianness comes in two forms - big and little.

Example: Imagine the 32bit integer number ```16,909,060``` in decimal.

In hexadecimal that would be ~+```0x01020304```+~. 
 ```0x01``` is the most significant byte (the one that increases the value the most.   is the least significant byte (as it increases the value the least).

When that is stored in memory on a little-endian system they are stored with the least significant byte first, producing the byte stream:
 ```0x04 0x03 0x02 0x01```

When that is stored in memory on a big-endian system they are stored with the most significant byte first, producing the byte stream:
 ```0x01 0x02 0x03 0x04```

For further information about endianness read the Wikipedia article on the subject.

SDL_BYTEORDER is a macro that corresponds to the byte order used by the processor type it was compiled for.


<<FullSearchCached(category:CategoryEndian -CategoryEnum -CategoryStruct -title:SGFunctions)>>


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.