• Home
  • Blog
  • University of San Francisco Base Conversion Tool Using Command Line Project

University of San Francisco Base Conversion Tool Using Command Line Project

0 comments

I’m working on a Computer Science exercise and need support.

  1. Implement a base conversion tool called nt. It converts numbers expressed in bases 2, 10, and 16 into the other two bases.
  2. use command line arguments in C
  3. You must implement the base conversions yourself, without using C library printf(), scanf(), or atoi()
  4. Examples:

$ ./nt 10 -o 2

0b1010

$ ./nt 0xFF -o 10

255

$ ./nt 0b11011110101011011011111011101111 -o 16

0xDEADBEEF
$ ./nt 0b11111111111111111111111111111111 -o 10
4294967295
$ ./nt 0x0000000B -o 10
11
$ ./nt 0b123 -o 2
Bad input

—————————————————————-

  1. Pseudocode: uint32_t string_to_int(char *str);
    init retval to 0
    init placeval to 1 (anything to the 0 power is 1)
    loop over str from the highest index down to 0
    calculate the integer corresponding to the character at that index
    calculate the value of that place by multiplying the integer * placeval
    add the value to the retval
    update to placeval to placeval * base
    return the return value
  2. Pseudocode: void int_to_string(uint32_t value, char *str, int base);
    init buffer to empty
    while value != 0
    quot = value / base
    rem = value % base
    calculate the character value of rem
    append the character value to the buffer
    value = quot
    copy buffer into str in reverse order

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}