[PATCH 05/11] Add utility functions to convert uints to bytes

Anton Lundin glance at acc.umu.se
Fri Nov 21 12:28:32 PST 2014


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..ee68b93 100644
--- a/src/array.c
+++ b/src/array.c
@@ -162,6 +162,16 @@ array_uint32_le (const unsigned char data[])
 
 
 unsigned int
+uint32_le_array (const unsigned int input, unsigned char data[])
+{
+	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[])
 {
 	return (data[0] << 16) + (data[1] << 8) + data[2];
@@ -169,6 +179,15 @@ array_uint24_be (const unsigned char data[])
 
 
 unsigned int
+uint24_be_array (const unsigned int input, unsigned char data[])
+{
+	data[0] = input >> 16 & 0xFF;
+	data[1] = input >>  8 & 0xFF;
+	data[2] = input & 0xFF;
+}
+
+
+unsigned int
 array_uint24_le (const unsigned char data[])
 {
 	return data[0] + (data[1] << 8) + (data[2] << 16);
diff --git a/src/array.h b/src/array.h
index b08ed2e..697b87e 100644
--- a/src/array.h
+++ b/src/array.h
@@ -56,9 +56,15 @@ unsigned int
 array_uint32_le (const unsigned char data[]);
 
 unsigned int
+uint32_le_array (const unsigned int input, unsigned char data[]);
+
+unsigned int
 array_uint24_be (const unsigned char data[]);
 
 unsigned int
+uint24_be_array (const unsigned int input, unsigned char data[]);
+
+unsigned int
 array_uint24_le (const unsigned char data[]);
 
 unsigned short
-- 
1.9.1



More information about the devel mailing list