From bee28e8a01c70bae522ef12947c296f837110dbe Mon Sep 17 00:00:00 2001 From: sparky4 Date: Mon, 5 Dec 2016 08:32:44 -0600 Subject: [PATCH] db.exe added as a utility --- makefile | 5 ++++- src/db.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 src/db.c diff --git a/makefile b/makefile index 2d46a27c..1c1cd5ce 100755 --- 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 index 00000000..d048517b --- /dev/null +++ b/src/db.c @@ -0,0 +1,31 @@ +#include /* printf */ +#include /* strcat */ +#include /* 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; +} -- 2.39.2