albatross / Mbed 2 deprecated Laurus_acc_gyro

Dependencies:   mbed

Fork of Laurus_acc_gyro by LAURUS

Revision:
0:5e220b09d315
diff -r 000000000000 -r 5e220b09d315 toString.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toString.cpp	Mon Apr 13 08:10:05 2015 +0000
@@ -0,0 +1,17 @@
+#include "toString.h"
+
+void ToBinaryString(char* dest, int destSize, const int integer, int byteNum) {
+    memset(dest, 0, destSize*sizeof(char));
+    strcat(dest, "0b");
+    if(byteNum > 4) {
+        strcat(dest, "########");
+        return;
+    }
+    for(int i=1; i<=8*byteNum; i++) {
+        if(integer & (1<<(8*byteNum-i))) {
+            strcat(dest, "1");
+        } else {
+            strcat(dest, "0");
+        }
+    }
+}
\ No newline at end of file