1 #include <bitfield/bitfield.h>
6 #define NIBBLE_SIZE (CHAR_BIT / 2)
8 uint8_t getNibble(const uint8_t source[], const uint8_t source_length,
9 const uint8_t nibble_index) {
10 uint8_t byte_index = nibble_index / 2;
11 uint8_t result = getByte(source, source_length, byte_index);
12 if(nibble_index % 2 == 0) {
13 result >>= NIBBLE_SIZE;
15 result &= bitmask(NIBBLE_SIZE);
19 uint8_t getByte(const uint8_t source[], const uint8_t source_length,
20 const uint8_t byte_index) {
21 if(byte_index < source_length) {
22 return source[byte_index];