helos1/memory/test_take_bitfield.c

17 lines
476 B
C
Raw Normal View History

2021-10-10 14:39:17 +08:00
#include <stdio.h>
#include <stdint.h>
inline static uint64_t takeBitfield(uint64_t v, int high, int low) {
return (v >> low) & ((1 << (high - low + 1)) - 1);
}
int main() {
uint64_t val = 0x400CD696E37AE;
printf("val = %lX\n", val);
printf("val[21:5] = %lX\n", takeBitfield(val, 21, 5));
printf("val[33:12] = %lX\n", takeBitfield(val, 33, 12));
printf("val[21:5] = %lX\n", takeBitfield(val, 21, 5));
printf("val[21:5] = %lX\n", takeBitfield(val, 21, 5));
}