about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorphoebos <ben@bvnf.space>2021-07-11 20:51:04 +0100
committerphoebos <ben@bvnf.space>2021-07-11 20:51:04 +0100
commit4948fa51e1f3d1f38cb2b7b83911692ca0bd4d43 (patch)
tree1dbc85b51758fb211ee1833bc0e2f7a458144eca
parent329d084f34662e023b1be9014118693bfb4ea5a9 (diff)
downloadkandr-4948fa51e1f3d1f38cb2b7b83911692ca0bd4d43.tar.gz
function to print chars in binary format for debugging
-rw-r--r--printf_binary.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/printf_binary.c b/printf_binary.c
new file mode 100644
index 0000000..b36dcc9
--- /dev/null
+++ b/printf_binary.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+void bp(char n){
+    /* prints chars up to value 255 (for 255, the MSB is 2^7 == 128) */
+    int i = 128;
+    while (i) {
+        printf("%c", ((n & i) == i) ? '1' : '0');
+        i >>= 1;
+    }
+}