]> 4ch.mooo.com Git - 16.git/blobdiff - src/util/db.c
trying to figure out the issue with player sprite with pcx i have no idea wwww
[16.git] / src / util / db.c
diff --git a/src/util/db.c b/src/util/db.c
new file mode 100755 (executable)
index 0000000..d048517
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdio.h>      /* printf */
+#include <string.h>     /* strcat */
+#include <stdlib.h>     /* strtol */
+
+const char *byte_to_binary(int x)
+{
+       static char b[9];
+       int z;
+
+       b[0] = '\0';
+       for (z = 128; z > 0; z >>= 1)
+       {
+               strcat(b, ((x & z) == z) ? "1" : "0");
+       }
+       return b;
+}
+
+void main()
+{
+       /* binary string to int */
+       char *tmp;
+       char *b = "1101";
+
+       printf("%d\n", strtol(b, &tmp, 2));
+       printf("%x\n", strtol(b, &tmp, 2));
+
+       /* byte to binary string */
+       printf("%s\n", byte_to_binary(4));
+       printf("%s\n", byte_to_binary(16));
+//    return 0;
+}