Mercurial > hg > octave-shane > gnulib-hg
changeset 10389:ca193e11eaaf
bitrotate: Add 8 bit rotate functions.
author | Simon Josefsson <simon@josefsson.org> |
---|---|
date | Mon, 01 Sep 2008 13:55:05 +0200 |
parents | 2710cb64f5be |
children | 247990850251 |
files | ChangeLog lib/bitrotate.h modules/bitrotate |
diffstat | 3 files changed, 21 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2008-09-01 Simon Josefsson <simon@josefsson.org> + * lib/bitrotate.h (rotl8, rotr8): Add. + * modules/bitrotate (configure.ac): Need AC_REQUIRE([AC_C_INLINE]). (Description): Mention stdint.h. Reported by Bruno Haible
--- a/lib/bitrotate.h +++ b/lib/bitrotate.h @@ -57,4 +57,22 @@ return ((x >> n) | (x << (16 - n))) & 0xFFFF; } +/* Given an unsigned 8-bit argument X, return the value corresponding + to rotating the bits N steps to the left. N must be between 1 to 7 + inclusive. */ +static inline uint8_t +rotl8 (uint8_t x, int n) +{ + return ((x << n) | (x >> (8 - n))) & 0xFF; +} + +/* Given an unsigned 8-bit argument X, return the value corresponding + to rotating the bits N steps to the right. N must be in 1 to 7 + inclusive. */ +static inline uint8_t +rotr8 (uint8_t x, int n) +{ + return ((x >> n) | (x << (8 - n))) & 0xFF; +} + #endif /* _GL_BITROTATE_H */