summaryrefslogtreecommitdiff
path: root/src/big_endian.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/big_endian.c')
-rw-r--r--src/big_endian.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/big_endian.c b/src/big_endian.c
new file mode 100644
index 0000000..2db8624
--- /dev/null
+++ b/src/big_endian.c
@@ -0,0 +1,28 @@
+#include "big_endian.h"
+
+void to_big_endian(uint64_t num, unsigned char *result)
+{
+ *(result+0) = (num >> 56) & 0xff;
+ *(result+1) = (num >> 48) & 0xff;
+ *(result+2) = (num >> 40) & 0xff;
+ *(result+3) = (num >> 32) & 0xff;
+ *(result+4) = (num >> 24) & 0xff;
+ *(result+5) = (num >> 16) & 0xff;
+ *(result+6) = (num >> 8) & 0xff;
+ *(result+7) = (num >> 0) & 0xff;
+}
+
+uint64_t from_big_endian(unsigned char *num)
+{
+ uint64_t result = ((uint64_t) (*num) << 56);
+
+ result += ((uint64_t) (*(num+1)) << 48);
+ result += ((uint64_t) (*(num+2)) << 40);
+ result += ((uint64_t) (*(num+3)) << 32);
+ result += ((uint64_t) (*(num+4)) << 24);
+ result += ((uint64_t) (*(num+5)) << 16);
+ result += ((uint64_t) (*(num+6)) << 8);
+ result += ((uint64_t) (*(num+7)) << 0);
+
+ return result;
+}