]> 4ch.mooo.com Git - 16.git/commitdiff
db.exe added as a utility
authorsparky4 <sparky4@cock.li>
Mon, 5 Dec 2016 14:32:44 +0000 (08:32 -0600)
committersparky4 <sparky4@cock.li>
Mon, 5 Dec 2016 14:32:44 +0000 (08:32 -0600)
makefile
src/db.c [new file with mode: 0755]

index 2d46a27c60a9e824abf86a8fbb1eb806cbb4ac9a..1c1cd5cede9e1039ae11d302d48b81c51cf238c0 100755 (executable)
--- a/makefile
+++ b/makefile
@@ -174,7 +174,8 @@ TESTEXEC2 = &
        pcxtest2.exe
 UTILEXEC = &
        palettel.exe &
-       palettec.exe
+       palettec.exe &
+       db.exe
 EXEC = &
        16.exe &
        bakapi.exe &
@@ -220,6 +221,7 @@ maptest.exe:        maptest.$(OBJ) 16_map.$(OBJ) 16_head.$(OBJ) gfx.lib $(DOSLIBLIBS)
 fmemtest.exe:   fmemtest.$(OBJ)
 exmmtest.exe:   exmmtest.$(OBJ) $(16LIB) $(DOSLIBLIBS)
 vgmtest.exe:   vgmtest.$(OBJ) vgmsnd.lib $(16LIB) $(DOSLIBLIBS)
+db.exe:                db.$(OBJ)
 
 #
 # executable's objects
@@ -251,6 +253,7 @@ inputest.$(OBJ):$(SRC)/inputest.c
 #tsthimem.$(OBJ): $(SRC)/tsthimem.c
 exmmtest.$(OBJ):$(SRC)/exmmtest.c
 vgmtest.$(OBJ):$(SRC)/vgmtest.c
+db.$(OBJ):$(SRC)/db.c
 
 #
 # non executable objects libraries
diff --git a/src/db.c b/src/db.c
new file mode 100755 (executable)
index 0000000..d048517
--- /dev/null
+++ b/src/db.c
@@ -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;
+}