From: Niels Möller Date: Wed, 16 Jan 2002 19:58:41 +0000 (+0100) Subject: (READ_UINT24, WRITE_UINT24, READ_UINT16, WRITE_UINT16): X-Git-Tag: nettle_1.5_release_20020131~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20b8bd9b454a511e25165dc285e527355be6ebb6;p=thirdparty%2Fnettle.git (READ_UINT24, WRITE_UINT24, READ_UINT16, WRITE_UINT16): New macros. Rev: src/nettle/macros.h:1.6 --- diff --git a/macros.h b/macros.h index c235600a..89400c54 100644 --- a/macros.h +++ b/macros.h @@ -40,6 +40,29 @@ do { \ (p)[3] = (i) & 0xff; \ } while(0) +/* Analogous macros, for 24 and 16 bit numbers */ +#define READ_UINT24(p) \ +( (((uint32_t) (p)[0]) << 16) \ + | (((uint32_t) (p)[1]) << 8) \ + | ((uint32_t) (p)[2])) + +#define WRITE_UINT24(p, i) \ +do { \ + (p)[0] = ((i) >> 16) & 0xff; \ + (p)[1] = ((i) >> 8) & 0xff; \ + (p)[2] = (i) & 0xff; \ +} while(0) + +#define READ_UINT16(p) \ +( (((uint32_t) (p)[0]) << 8) \ + | ((uint32_t) (p)[1])) + +#define WRITE_UINT16(p, i) \ +do { \ + (p)[0] = ((i) >> 8) & 0xff; \ + (p)[1] = (i) & 0xff; \ +} while(0) + /* And the other, little-endian, byteorder */ #define LE_READ_UINT32(p) \ ( (((uint32_t) (p)[3]) << 24) \