Patchwork [02,of,11,c-hglib:level0,V2] utils: swap_uint32 function

login
register
mail settings
Submitter Iulian Stana
Date Sept. 13, 2013, 8:31 p.m.
Message ID <1c3f11950b3e4a267c69.1379104312@doppler>
Download mbox | patch
Permalink /patch/2436/
State Deferred, archived
Headers show

Comments

Iulian Stana - Sept. 13, 2013, 8:31 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1379102653 -10800
#      Fri Sep 13 23:04:13 2013 +0300
# Node ID 1c3f11950b3e4a267c6973e6682beaf90a94bb2b
# Parent  61c230dad6595f35cf22d2b3c0f64df039e8fb18
utils: swap_uint32 function

Swap from Big endian to Little endian and vice versa.

Patch

diff --git a/utils.c b/utils.c
new file mode 100644
--- /dev/null
+++ b/utils.c
@@ -0,0 +1,17 @@ 
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "utils.h"
+
+/* 
+ * Byte swap unsigned int
+ * */
+uint32_t swap_uint32(uint32_t val)
+{
+	val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF);
+	return (val << 16) | (val >> 16);
+}
+
diff --git a/utils.h b/utils.h
new file mode 100644
--- /dev/null
+++ b/utils.h
@@ -0,0 +1,13 @@ 
+#ifndef _UTILS_CHG_H_
+#define _UTILS_CHG_H_
+
+#include <stdint.h>
+
+/** 
+ * \brief Byte swap unsigned int
+ * \param val an uint32_t integer
+ * \retval uint32_t the bigendian form of val value
+ * */
+uint32_t swap_uint32( uint32_t val );
+
+#endif