summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-29 15:15:16 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-29 15:15:16 -0500
commit518430f122772016715660086a630ff595e4fcfd (patch)
treea3cbf7dd200101c5051a97a0dc023f33ab4867db /src
parent9817085bc127532b9724d80e16343cb78e3ca27a (diff)
Add a function to set a single nibble in a bitarray.
Diffstat (limited to 'src')
-rw-r--r--src/bitfield/bitfield.c6
-rw-r--r--src/bitfield/bitfield.h3
2 files changed, 9 insertions, 0 deletions
diff --git a/src/bitfield/bitfield.c b/src/bitfield/bitfield.c
index af17d485..ae1be403 100644
--- a/src/bitfield/bitfield.c
+++ b/src/bitfield/bitfield.c
@@ -21,3 +21,9 @@ uint8_t get_byte(const uint8_t source[], const uint8_t source_length,
}
return 0;
}
+
+bool set_nibble(const uint16_t nibble_index, const uint8_t value,
+ uint8_t* destination, const uint16_t destination_length) {
+ return copy_bits(&value, CHAR_BIT, NIBBLE_SIZE, NIBBLE_SIZE, destination,
+ destination_length, nibble_index * NIBBLE_SIZE);
+}
diff --git a/src/bitfield/bitfield.h b/src/bitfield/bitfield.h
index b58e4e59..990482fc 100644
--- a/src/bitfield/bitfield.h
+++ b/src/bitfield/bitfield.h
@@ -110,6 +110,9 @@ bool copy_bits_right_aligned(const uint8_t source[], const uint16_t source_lengt
const uint16_t offset, const uint16_t bit_count,
uint8_t* destination, const uint16_t destination_length);
+bool set_nibble(const uint16_t nibble_index, const uint8_t value,
+ uint8_t* destination, const uint16_t destination_length);
+
#ifdef __cplusplus
}
#endif