diff options
author | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2014-01-02 17:56:20 -0500 |
---|---|---|
committer | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2014-01-02 17:56:45 -0500 |
commit | 31caa9c77dbfc438a104fbcab6db5165528c0f89 (patch) | |
tree | 62f4d0741eb47dc09db717f6cc40432163cb5b7d /src/bitfield/8byte.c | |
parent | 4af52c415f1668fbd168da74d0aca903c592463f (diff) |
Clarify when you need to specify endianness.
Diffstat (limited to 'src/bitfield/8byte.c')
-rw-r--r-- | src/bitfield/8byte.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/bitfield/8byte.c b/src/bitfield/8byte.c index e3eddf20..d3160934 100644 --- a/src/bitfield/8byte.c +++ b/src/bitfield/8byte.c @@ -11,24 +11,25 @@ uint64_t bitmask(const uint8_t bit_count) { } uint8_t eightbyte_get_nibble(const uint64_t source, const uint8_t nibble_index, - const bool big_endian) { + const bool data_is_big_endian) { return get_bit_field(source, NIBBLE_SIZE * nibble_index, NIBBLE_SIZE, - big_endian); + data_is_big_endian); } -uint8_t eightbyte_get_byte(const uint64_t source, const uint8_t byte_index, - const bool big_endian) { - // TODO we're not handling swapped endianness - we could use get_bit_field - // but this might be more efficient +uint8_t eightbyte_get_byte(uint64_t source, const uint8_t byte_index, + const bool data_is_big_endian) { + if(data_is_big_endian) { + source = __builtin_bswap64(source); + } return (source >> (EIGHTBYTE_BIT - ((byte_index + 1) * CHAR_BIT))) & 0xFF; } uint64_t get_bit_field(uint64_t source, const uint16_t offset, - const uint16_t bit_count, const bool big_endian) { + const uint16_t bit_count, const bool data_is_big_endian) { int startByte = offset / CHAR_BIT; int endByte = (offset + bit_count - 1) / CHAR_BIT; - if(!big_endian) { + if(!data_is_big_endian) { source = __builtin_bswap64(source); } |