[PATCH v2 07/15] Add utility functions to convert uints to bytes

Anton Lundin glance at acc.umu.se
Wed Dec 17 14:11:04 PST 2014


Reviewed-by: Jef Driesen <jef at libdivecomputer.org>
Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 src/array.c | 19 +++++++++++++++++++
 src/array.h |  6 ++++++
 2 files changed, 25 insertions(+)

diff --git a/src/array.c b/src/array.c
index 243ec34..be8d696 100644
--- a/src/array.c
+++ b/src/array.c
@@ -161,6 +161,16 @@ array_uint32_le (const unsigned char data[])
 }
 
 
+void
+array_uint32_le_set (unsigned char data[], const unsigned int input)
+{
+	data[0] = input & 0xFF;
+	data[1] = (input >>  8) & 0xFF;
+	data[2] = (input >> 16) & 0xFF;
+	data[3] = (input >> 24) & 0xFF;
+}
+
+
 unsigned int
 array_uint24_be (const unsigned char data[])
 {
@@ -168,6 +178,15 @@ array_uint24_be (const unsigned char data[])
 }
 
 
+void
+array_uint24_be_set (unsigned char data[], const unsigned int input)
+{
+	data[0] = (input >> 16) & 0xFF;
+	data[1] = (input >>  8) & 0xFF;
+	data[2] = input & 0xFF;
+}
+
+
 unsigned int
 array_uint24_le (const unsigned char data[])
 {
diff --git a/src/array.h b/src/array.h
index b08ed2e..622e0d5 100644
--- a/src/array.h
+++ b/src/array.h
@@ -55,9 +55,15 @@ array_uint32_be (const unsigned char data[]);
 unsigned int
 array_uint32_le (const unsigned char data[]);
 
+void
+array_uint32_le_set (unsigned char data[], const unsigned int input);
+
 unsigned int
 array_uint24_be (const unsigned char data[]);
 
+void
+array_uint24_be_set (unsigned char data[], const unsigned int input);
+
 unsigned int
 array_uint24_le (const unsigned char data[]);
 
-- 
2.1.0



More information about the devel mailing list