Question: Write a C program which: 1 . Takes command - line arguments representing unsigned integers in decimal, octal ( 0 . . . ) ,

Write a C program which:
1. Takes command-line arguments representing unsigned integers in decimal, octal
(0...), hex (0x...), or binary (0b...) formats.
2. Uses strtoul() to convert to unsigned int.
Note that using base=0, strtoul() will recognize decimal, octal, and hex formats, but not
binary. To convert from binary format use base=2 and skip the "0b" part, e.g. char *e;
unsigned long int xl = strtoul("101",&e,2); will set xl to 5 and *e will be 0.
3. Displays an error message for bad arguments.
4. Displays the value in decimal, hex, and binary.
5. Displays the bit-reversed value in decimal, hex, and binary.
Assume that unsigned int uses 32 bits.
To check for strtoul() failure, #include and before calling strtoul()
set errno=0; then after calling strtoul(), if errno is not zero call perror ("strtoul");. For other
bad arguments print an error message to standard error, i.e. fprintf( stderr, "format...", ...);
Test with some good arguments: 120120x120b101100111
Sample run:
$ ./bits 0x1234123abcefg 0b101100111000
0x1234=4660=0x00001234=0b00000000000000000001001000110100
bitrev =742916096=0x2c480000=0b00101100010010000000000000000000
convert: bad argument: 123abcefg
123abcefg =123=0x0000007b =0b00000000000000000000000001111011
bitrev =3724541952=0xde000000=0b11011110000000000000000000000000
0b101100111000=2872=0x00000b38=0b00000000000000000000101100111000
ECE3600
Operating Systems
bitrev =483393536=0x1cd00000=0b00011100110100000000000000000000
$

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!