Add binary output helper for assembler
x1phosura x1phosura@x1phosura.zone
Sat, 27 Aug 2022 23:22:49 -0700
1 files changed,
30 insertions(+),
0 deletions(-)
jump to
A
projects/06/bin2text.c
@@ -0,0 +1,30 @@
+#include <stdio.h> +#include <stdint.h> + +void output_binary(uint8_t b) +{ + char i, msb; + + for (i = 0; i < 8; ++i) { + msb = b & 0x80; + if (msb) + putchar('1'); + else + putchar('0'); + b <<= 1; + } +} + +int main(int argc, char *argv[]) +{ + char c, next_line = 0; + + while ((c = getchar()) != EOF) { + output_binary(c); + ++next_line; + if (next_line % 2 == 0) + putchar('\n'); + } + + return 0; +}