D. J. Bernstein

The uint32 library interface

32-bit integers

     #include <uint32.h>

     uint32 u;
uint32 is a 32-bit unsigned integer type, normally either unsigned int or unsigned long.

Little-endian 32-bit integers

     #include <uint32.h>

     uint32_pack(s,u);
     uint32_unpack(s,&u);

     uint32 u;
     char s[4];
uint32_pack finds integers u0, u1, u2, u3 between 0 and 255 inclusive such that u equals u0+256*u1+65536*u2+16777216*u3. It then stores u0 in s[0], u1 in s[1], u2 in s[2], and u3 in s[3].

uint32_unpack extracts u0 from s[0], u1 from s[1], u2 from s[2], and u3 from s[3]. It then sets u to u0+256*u1+65536*u2+16777216*u3.

Big-endian 32-bit integers

     #include <uint32.h>

     uint32_pack_big(s,u);
     uint32_unpack_big(s,&u);

     uint32 u;
     char s[4];
uint32_pack_big finds integers u0, u1, u2, u3 between 0 and 255 inclusive such that u equals u0+256*u1+65536*u2+16777216*u3. It then stores u0 in s[3], u1 in s[2], u2 in s[1], and u3 in s[0].

uint32_unpack_big extracts u0 from s[3], u1 from s[2], u2 from s[1], and u3 from s[0]. It then sets u to u0+256*u1+65536*u2+16777216*u3.