/******************************************/ /* integer.h 0.0.0 (1999-Oct-17-Sun) */ /* Adam M. Costello */ /******************************************/ /* Convert integers to and from arrays of bytes. */ /* This is ANSI C code. */ #ifndef INTEGER_H #define INTEGER_H #include /* uint16 is an unsigned integral type */ /* with at least 16 bits (but maybe more): */ typedef unsigned int uint16; #define UINT16_MAX UINT_MAX /* uint32 is an unsigned integral type */ /* with at least 32 bits (but maybe more): */ #if UINT_MAX >= 0xffffffff typedef unsigned int uint32; #define UINT32_MAX UINT_MAX #else typedef unsigned long uint32; #define UINT32_MAX ULONG_MAX #endif void encode_uint16(unsigned char *bytes, uint16 n); /* Encodes an integer, which must be in the range */ /* 0..0xffff, as two bytes, most significant byte */ /* first. The pointer must point to an array of */ /* at least two characters. */ void encode_uint32(unsigned char *bytes, uint32 n); /* Encodes an integer, which must be in the range 0..0xffff, */ /* as four bytes, most significant byte first. The pointer */ /* must point to an array of at least four characters. */ uint16 decode_uint16(const unsigned char *bytes); /* Interprets the first two characters of the array, which must */ /* each be in the range 0..0xff, as an unsigned integer, most */ /* significant byte first, and returns the result. */ uint32 decode_uint32(const unsigned char *bytes); /* Interprets the first four characters of the array, which */ /* must each be in the range 0..0xff, as an unsigned integer, */ /* most significant byte first, and returns the result. */ #endif /* INTEGER_H */