diff --git a/qscr/c/bits/converter/converter.c b/qscr/c/bits/converter/converter.c new file mode 100644 index 0000000..73e7880 --- /dev/null +++ b/qscr/c/bits/converter/converter.c @@ -0,0 +1,47 @@ +#include +#include + +/* + take input + decide if hex or binary + then convert + then print + + let's convert binary to hex first + for each byte, split into nibble, + +*/ + + +//might have to add some padding, but basic works +void bintohex(char* string_in){ + const char hexmap[] = "0123456789ABCDEF"; + char hexnum[4]; + int stringl = strnlen(string_in, 10)-1; + //aantal nibbles + int loopamount = stringl/4; + printf("totalstringlength=%d\n", stringl); + for (int loopcount = 0; loopcount < loopamount; loopcount++) { + int bin2dec = 0; + //rechts naar links in nibble + for (int nibbledigit = 0 ; nibbledigit <4 ; nibbledigit++) { + //nibblecount + current + int targetdigit = loopcount*4+(4-1-nibbledigit); + //check if j+i = 1 + //printf("nibbledigit:%d=%c=%i\n", j, string_in[targetdigit],1<