Write a program that takes a single command line argument and outputs the unsigned integer from the command line argument in binary form. Assume the integer is in hexadecimal format.
Examples:
cmw@paris:~/cs520/p1/binary_print$ ./binary_print 0 0000 0000 0000 0000 0000 0000 0000 0000
cmw@paris:~/cs520/p1/binary_print$ ./binary_print ffee 0000 0000 0000 0000 1111 1111 1110 1110
cmw@paris:~/cs520/p1/binary_print$ ./binary_print 0D800 0000 0000 0000 0000 1101 1000 0000 0000
cmw@paris:~/cs520/p1/binary_print$ ./binary_print 0DFFF 0000 0000 0000 0000 1101 1111 1111 1111
cmw@paris:~/cs520/p1/binary_print$ ./binary_print ffffff09 1111 1111 1111 1111 1111 1111 0000 1001
cmw@paris:~/cs520/p1/binary_print$ ./binary_print Not enough command line arguments cmw@paris:~/cs520/p1/binary_print$ ./binary_print ff ff Too many command line arguments
cmw@paris:~/cs520/p1/binary_print$ ./binary_print ffffffffff ffffffffff is not a valid number (overflow)
cmw@paris:~/cs520/p1/binary_print$ ./binary_print chris chris is not a valid number
cmw@paris:~/cs520/p1/binary_print$ ./binary_print 123III 123III is not a valid number cmw@paris:~/cs520/p1/binary_print$ ./binary_print III123 III123 is not a valid number
cmw@paris:~/cs520/p1/binary_print$ ./binary_print -0xffff -0xffff is not a valid number (overflow)
cmw@paris:~/cs520/p1/binary_print$ ./binary_print 0x0 0000 0000 0000 0000 0000 0000 0000 0000 cmw@paris:~/cs520/p1/binary_print$ ./binary_print 0 0000 0000 0000 0000 0000 0000 0000 0000
We will walk through the process of writing this program, and will build it one line at a time. If you have any questions about what a particular bit of code does, please feel free to stop me and ask questions.
In order to make sure that all students are doing the same thing, we should all be working on either agate, or on one of the computers in this lab room.
We should also all compile with the same command, and the same flags. We will be using:
gcc -Wall -std=c99 binary_print.c -o binary_print