diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-09-01 13:55:05 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-09-01 13:55:05 +0200 |
commit | e6a0d376a9b44cadd66d06e76d0c9181c20e4102 (patch) | |
tree | 65dd04fe9bfd7f2a3da741221fd07a6962b5bfa9 | |
parent | ac5bd11a2348f7105163d9c7df38a046972a3f82 (diff) | |
download | gnulib-e6a0d376a9b44cadd66d06e76d0c9181c20e4102.tar.gz |
bitrotate: Add 8 bit rotate functions.
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | lib/bitrotate.h | 18 | ||||
-rw-r--r-- | modules/bitrotate | 2 |
3 files changed, 21 insertions, 1 deletions
@@ -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 diff --git a/lib/bitrotate.h b/lib/bitrotate.h index 8123a5c7f4..1ac1cff42b 100644 --- a/lib/bitrotate.h +++ b/lib/bitrotate.h @@ -57,4 +57,22 @@ rotr16 (uint16_t x, int n) 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 */ diff --git a/modules/bitrotate b/modules/bitrotate index 13bd97e313..63124a89e0 100644 --- a/modules/bitrotate +++ b/modules/bitrotate @@ -1,5 +1,5 @@ Description: -Rotate bits in 16 and 32 bit integers. +Rotate bits in unsigned 8, 16, and 32 bit integers. Files: lib/bitrotate.h |