~jkaivo/binary

c8c21c5f650596454ec5619da8c911569baa6b42 — Jakob Kaivo 3 years ago 52b735b binary
include sample program binhex
3 files changed, 32 insertions(+), 0 deletions(-)

A .gitignore
A Makefile
A binhex.c
A .gitignore => .gitignore +2 -0
@@ 0,0 1,2 @@
binhex
*.o

A Makefile => Makefile +9 -0
@@ 0,0 1,9 @@
.POSIX:

binhex: binhex.o binary.o

binhex.o: binhex.c binary.h
binary.o: binary.c binary.h

clean:
	rm -f binhex *.o

A binhex.c => binhex.c +21 -0
@@ 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;
}