support function

This commit is contained in:
iceman1001 2024-04-22 09:29:38 +02:00
commit ac809c4a9f
2 changed files with 11 additions and 0 deletions

View file

@ -144,6 +144,16 @@ uint32_t reflect32(uint32_t b) {
return v;
}
uint64_t reflect64(uint64_t b) {
// https://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
uint64_t v = b; // 32-bit word to reverse bit order
// swap 2-byte long pairs
uint64_t v1 = reflect32(v >> 32);
uint64_t v2 = reflect32(v);
v = (v1 << 32) | (v2 & 0xFFFFFFFF);
return v;
}
void num_to_bytes(uint64_t n, size_t len, uint8_t *dest) {
while (len--) {
dest[len] = (uint8_t) n;