aboutsummaryrefslogtreecommitdiffstats
path: root/src/bitfield/8byte.c
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-04 10:51:16 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-04 10:52:42 -0500
commit08db5c9eb826f7aa0dba36cbef8011d7bc6b55a5 (patch)
treeb2875552387f00191c772bc6da08dcaa7e6d2e87 /src/bitfield/8byte.c
parent6f3a81ed8287357b54aad16bff27495c6eaca6df (diff)
Add a get_bitfield function for byte arrays.
Diffstat (limited to 'src/bitfield/8byte.c')
-rw-r--r--src/bitfield/8byte.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/bitfield/8byte.c b/src/bitfield/8byte.c
index 76dccc75..3c555f08 100644
--- a/src/bitfield/8byte.c
+++ b/src/bitfield/8byte.c
@@ -8,7 +8,7 @@
uint8_t eightbyte_get_nibble(const uint64_t source, const uint8_t nibble_index,
const bool data_is_big_endian) {
- return eightbyte_get_bit_field(source, NIBBLE_SIZE * nibble_index, NIBBLE_SIZE,
+ return eightbyte_get_bitfield(source, NIBBLE_SIZE * nibble_index, NIBBLE_SIZE,
data_is_big_endian);
}
@@ -20,7 +20,10 @@ 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 eightbyte_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;
@@ -33,8 +36,7 @@ uint64_t eightbyte_get_bit_field(uint64_t source, const uint16_t offset,
uint64_t ret = bytes[startByte];
if(startByte != endByte) {
// The lowest byte address contains the most significant bit.
- int i;
- for(i = startByte + 1; i <= endByte; i++) {
+ for(uint8_t i = startByte + 1; i <= endByte; i++) {
ret = ret << 8;
ret = ret | bytes[i];
}