Patchwork [02,of,14,RFC,c-hglib:level0] utils: swap_uint32 function

login
register
mail settings
Submitter Iulian Stana
Date Sept. 3, 2013, 8:30 p.m.
Message ID <a688f64ff7d890bd193f.1378240241@doppler>
Download mbox | patch
Permalink /patch/2307/
State Deferred, archived
Headers show

Comments

Iulian Stana - Sept. 3, 2013, 8:30 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1378233759 -10800
#      Tue Sep 03 21:42:39 2013 +0300
# Node ID a688f64ff7d890bd193fcfcbf5b667e11402c08f
# Parent  589054a6400c09ea613043d6529b526897ac8515
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,13 @@ 
+#include <stdint.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,12 @@ 
+#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 );
+