]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/util.c
1. small bugfix in hf 14a mifare
[proxmark3-svn] / client / util.c
index 2c02d119449667a95f9aebb7744784ae86840284..d691eefc4e1b8231e4caf57c368ee551cc747f8c 100644 (file)
@@ -1,5 +1,14 @@
-#include <stdio.h>
-#include <stdint.h>
+//-----------------------------------------------------------------------------
+// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
+//
+// This code is licensed to you under the terms of the GNU GPL, version 2 or,
+// at your option, any later version. See the LICENSE.txt file for the text of
+// the license.
+//-----------------------------------------------------------------------------
+// utilities
+//-----------------------------------------------------------------------------
+
+#include "util.h"
 
 void print_hex(const uint8_t * data, const size_t len)
 {
@@ -21,3 +30,22 @@ char * sprint_hex(const uint8_t * data, const size_t len) {
 
        return buf;
 }
+
+void num_to_bytes(uint64_t n, size_t len, uint8_t* dest)
+{
+       while (len--) {
+               dest[len] = (uint8_t) n;
+               n >>= 8;
+       }
+}
+
+uint64_t bytes_to_num(uint8_t* src, size_t len)
+{
+       uint64_t num = 0;
+       while (len--)
+       {
+               num = (num << 8) | (*src);
+               src++;
+       }
+       return num;
+}
Impressum, Datenschutz