aboutsummaryrefslogtreecommitdiff
path: root/tools/bin2hex.c
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-12-29 19:52:00 +0100
committerWojciech Kosior <kwojtus@protonmail.com>2020-12-29 19:52:00 +0100
commit5b6a3f3b216939a11ed1978d7da4dd6bbe4edc2a (patch)
tree597198cd0bf0df05df9b34ffef8a8681835cb825 /tools/bin2hex.c
parent30a97274bde7a1988d80861ab9b381148f3d19a7 (diff)
downloadAGH-engineering-thesis-5b6a3f3b216939a11ed1978d7da4dd6bbe4edc2a.tar.gz
AGH-engineering-thesis-5b6a3f3b216939a11ed1978d7da4dd6bbe4edc2a.zip
add a C program for translating binary files to format understood by Verilog
Diffstat (limited to 'tools/bin2hex.c')
-rw-r--r--tools/bin2hex.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/bin2hex.c b/tools/bin2hex.c
new file mode 100644
index 0000000..f4f2745
--- /dev/null
+++ b/tools/bin2hex.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int main(int argc, char **argv)
+{
+ int input;
+
+ while (1) {
+ input = getchar();
+
+ if (input == EOF)
+ break;
+
+ printf("%02x", input);
+
+ input = getchar();
+
+ /* If we have odd number of bytes, pad with a NULL-byte. */
+ if (input == EOF)
+ input = 0;
+
+ printf(" %02x\n", input);
+ }
+
+ return 0;
+}