// printf(" ip=%04x\n\n", _IP);\r
// printf(" cf=%04x\npf=%04x\naf=%04x\nzf=%04x\nsf=%04x\ntf=%04x\nif=%04x\ndf=%04x\nof=%04x\n", _CF, _PF, _AF, _ZF, _SF, _TF, _IF, _DF, _OF);\r
printf("cflag: "BYTE_TO_BINARY_PATTERN""BYTE_TO_BINARY_PATTERN"\n", BYTE_TO_BINARY(_cflag>>8), BYTE_TO_BINARY(_cflag));\r
+// printf("cflag: %s\n",(_cflag));\r
#endif\r
printf("dx: "BYTE_TO_BINARY_PATTERN""BYTE_TO_BINARY_PATTERN"\n", BYTE_TO_BINARY(_dx>>8), BYTE_TO_BINARY(_dx));\r
printf(" ---------------------------------------\n");\r
}\r
#endif\r
\r
-const char *word_to_binary(word x)\r
+//from https://stackoverflow.com/questions/18327439/printing-binary-representation-of-a-char-in-c\r
+const char *word_to_binary(int x)\r
{\r
static char b[17];\r
int z;\r
\r
b[0] = '\0';\r
- for (z = 16; z > 0; z >>= 1)\r
+ for (z = 256; z > 0; z >>= 1)\r
{\r
+/// printf(" z=%u b=%u x=%u\n", z, b, x);\r
strcat(b, ((x & z) == z) ? "1" : "0");\r
}\r
return b;\r
}\r
\r
-const char *nibble_to_binary(nibble x)\r
+const char *byte_to_binary(int x)\r
{\r
static char b[9];\r
int z;\r
\r
b[0] = '\0';\r
- for (z = 8; z > 0; z >>= 1)\r
+ for (z = 128; z > 0; z >>= 1)\r
{\r
strcat(b, ((x & z) == z) ? "1" : "0");\r
}\r
return b;\r
}\r
\r
-const char *boolean_to_binary(boolean x)\r
+const char *nibble_to_binary(int x)\r
{\r
static char b[9];\r
int z;\r
\r
+ b[0] = '\0';\r
+ for (z = 8; z > 0; z >>= 1)\r
+ {\r
+ strcat(b, ((x & z) == z) ? "1" : "0");\r
+ }\r
+ return b;\r
+}\r
+\r
+const char *boolean_to_binary(int x)\r
+{\r
+ static char b[3];\r
+ int z;\r
+\r
b[0] = '\0';\r
for (z = 1; z > 0; z >>= 1)\r
{\r
return b;\r
}\r
\r
+void wordtest()\r
+{\r
+ word pee;\r
+ printf("wordtest\n");\r
+ /* word to binary string */\r
+ for(pee=0;pee<280;pee++)\r
+ printf(" %u %s\n", pee, word_to_binary(pee));\r
+ printf(" sizeof(word)=%s\n", word_to_binary(sizeof(word)));\r
+ printf("end of word test\n");\r
+}\r
+\r
+void bytetest()\r
+{\r
+ byte pee;\r
+ printf("bytetest\n");\r
+ /* byte to binary string */\r
+ for(pee=0;pee<18;pee++)\r
+ printf(" %u %s\n", pee, byte_to_binary(pee));\r
+ printf(" sizeof(byte)=%s\n", byte_to_binary(sizeof(byte)));\r
+ printf("end of byte test\n");\r
+}\r
+\r
void nibbletest()\r
{\r
nibble pee;\r
printf("nibbletest\n");\r
/* nibble to binary string */\r
for(pee=0;pee<18;pee++)\r
- printf(" %u %s\n", pee, nibble_to_binary(pee));\r
+ printf(" %u %s\n", pee, nibble_to_binary(pee));\r
printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));\r
printf("end of nibble test\n");\r
}\r
printf("booleantest\n");\r
/* boolean to binary string */\r
for(pee=0;pee<4;pee++)\r
- printf(" %u %s\n", pee, boolean_to_binary(pee));\r
+ printf(" %u %s\n", pee, boolean_to_binary(pee));\r
printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));\r
printf("end of boolean test\n");\r
}\r