uint8_t eightbyte_get_nibble(const uint64_t source, const uint8_t nibble_index,
const bool data_is_big_endian) {
- return get_bit_field(source, NIBBLE_SIZE * nibble_index, NIBBLE_SIZE,
- data_is_big_endian);
+ return (uint8_t) eightbyte_get_bitfield(source, NIBBLE_SIZE * nibble_index,
+ NIBBLE_SIZE, data_is_big_endian);
}
uint8_t eightbyte_get_byte(uint64_t source, const uint8_t byte_index,
return (source >> (EIGHTBYTE_BIT - ((byte_index + 1) * CHAR_BIT))) & 0xFF;
}
-uint64_t get_bit_field(uint64_t source, const uint16_t offset,
+// TODO is this funciton necessary anymore? is it any faster for uint64_t than
+// get_bitfield(data[], ...)? is the performance better on a 32 bit platform
+// like the PIC32?
+uint64_t eightbyte_get_bitfield(uint64_t source, const uint16_t offset,
const uint16_t bit_count, const bool data_is_big_endian) {
int startByte = offset / CHAR_BIT;
int endByte = (offset + bit_count - 1) / CHAR_BIT;
uint64_t ret = bytes[startByte];
if(startByte != endByte) {
// The lowest byte address contains the most significant bit.
- int i;
+ uint8_t i;
for(i = startByte + 1; i <= endByte; i++) {
ret = ret << 8;
ret = ret | bytes[i];
return ret & bitmask(bit_count);
}
-bool set_bit_field(uint64_t* destination, uint64_t value, const uint16_t offset,
- const uint16_t bit_count) {
+bool eightbyte_set_bitfield(uint64_t value, const uint16_t offset,
+ const uint16_t bit_count, uint64_t* destination) {
if(value > bitmask(bit_count)) {
return false;
}