diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-24 01:05:44 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-24 01:05:44 +0200 |
commit | cf0f05362e71c189b8052bbfddd2f270f907041e (patch) | |
tree | 371ba96e6d0cdda94a5ba0f07628b1d1ea0c5960 /libhashsum_reverse_byte__.c | |
parent | Fix makefile (diff) | |
download | libhashsum-cf0f05362e71c189b8052bbfddd2f270f907041e.tar.gz libhashsum-cf0f05362e71c189b8052bbfddd2f270f907041e.tar.bz2 libhashsum-cf0f05362e71c189b8052bbfddd2f270f907041e.tar.xz |
Standardise how to interpret a partial byte
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum_reverse_byte__.c')
-rw-r--r-- | libhashsum_reverse_byte__.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libhashsum_reverse_byte__.c b/libhashsum_reverse_byte__.c new file mode 100644 index 0000000..c608eb0 --- /dev/null +++ b/libhashsum_reverse_byte__.c @@ -0,0 +1,12 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +uint8_t +libhashsum_reverse_byte__(uint8_t x) +{ + x = (uint8_t)(((x & 0xAAU) >> 1) | ((x << 1) & 0xAAU)); + x = (uint8_t)(((x & 0xCCU) >> 2) | ((x << 2) & 0xCCU)); + x = (uint8_t)(((x & 0xF0U) >> 4) | ((x << 4) & 0xF0U)); + return x; +} |