summaryrefslogtreecommitdiff
path: root/binhex.c
diff options
context:
space:
mode:
Diffstat (limited to 'binhex.c')
-rw-r--r--binhex.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/binhex.c b/binhex.c
new file mode 100644
index 0000000..1741573
--- /dev/null
+++ b/binhex.c
@@ -0,0 +1,21 @@
+#include <inttypes.h>
+#include <stdio.h>
+#include "binary.h"
+
+int main(int argc, char *argv[])
+{
+ for (int i = 1; i < argc; i++) {
+ int base = argv[i][0] == '0' && argv[i][1] == 'x' ? 16 : 2;
+ char s[BINSTRLEN];
+ uintmax_t n = strtoumax(argv[i], NULL, base);
+ if (argc > 2) {
+ printf("%s: ", argv[i]);
+ }
+ if (base == 2) {
+ printf("%jx\n", n);
+ } else {
+ printf("%s\n", binstr(sizeof(s), s, n));
+ }
+ }
+ return 0;
+}