1 #include <bitfield/bitfield.h>
6 uint64_t bitmask(const uint8_t bit_count) {
7 return (((uint64_t)0x1) << bit_count) - 1;
10 uint8_t get_nibble(const uint8_t source[], const uint8_t source_length,
11 const uint8_t nibble_index) {
12 uint8_t byte_index = nibble_index / 2;
13 uint8_t result = get_byte(source, source_length, byte_index);
14 if(nibble_index % 2 == 0) {
15 result >>= NIBBLE_SIZE;
17 result &= bitmask(NIBBLE_SIZE);
21 uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
22 const uint8_t byte_index) {
23 if(byte_index < source_length) {
24 return source[byte_index];
29 bool set_nibble(const uint16_t nibble_index, const uint8_t value,
30 uint8_t* destination, const uint16_t destination_length) {
31 return copy_bits(&value, CHAR_BIT, NIBBLE_SIZE, NIBBLE_SIZE, destination,
32 destination_length, nibble_index * NIBBLE_SIZE);