Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that: 1) converts an unsigned integer of a specified base to an

ID: 3558888 • Letter: W

Question

Write a program that: 1) converts an unsigned integer of a specified base to an unsigned integer of another specified base ; 2) converts a signed decimal integer to its 32-bit signed magnitude and 32-bit 2's complement hexadecimal representations, and 3) converts a float into its base 2 scientific notation . You may use class(es), if you wish, but they are not required.

Additional Specifications

For parts 1 and 2

1.1. You must read the input numbers into character arrays.

1.2. All conversions must be done explicitly by your program. You may not call atoi, atof, sprintf(), hex, %x, cast, or

any other built-in converting functions.

You may assume that all inputs will be valid. There is no need for error checking.

The only header file you may #include is iostream.

The format of your output must match mine exactly. We use diff to compare your output to mine to determine your

score.

Unsigned integer numbers.

5.1. You may assume that the unsigned integers will fit into a 64-bit unsigned long long.

5.2. The possible bases are 2-16 inclusive. For bases 11 to 16, you should use the letters A-F for digits valued greater

than 9.

5.3. Hint: Use a base 10 representation as an intermediate form for all combination of bases.

Signed integer numbers.
6.1. The input format will be [-][0-9]+, with no leading zeroes.

Float.

7.1. IEEE 32 bits (float): 31 sign bit, 23-30 exponent (with 127 offset), 0-22 mantissa (with implicit leading 1).

7.2. Your mantissa should have the implicit leading 1 prepended.

7.3. Hint: To make use of the bitwise operators you will need to convert your float to an integer. I used

Explanation / Answer

* Convert from any base to any other base. */   #include    #include    #include    #include       #define  MINBASE   2u               /* smallest base */   #define  MAXBASE  36u               /* largest base */      int main()   {     void displayValueAndBases(unsigned long num, int base, int newbase);     long getNumberInBaseN(unsigned int b);     int  getBase(unsigned int minbase, unsigned int maxbase);        int  base;                        /* initial base */     int  newbase;                     /* final base*/     unsigned long num;                /* initial value, in base 10 */        printf("Enter initial base: ");   /* grab initial base (in base 10) */     if ((base = getBase(MINBASE, MAXBASE)) != -1)     {                                       printf("Enter target base: ");             /* grab target base */       if ((newbase = getBase(MINBASE, MAXBASE)) != -1)       {         printf("Enter number to convert: ");     /* grab number */         while ((num = getNumberInBaseN(base)) != -1)         {                                        displayValueAndBases(num, base, newbase);           printf("Enter another base %i number to convert: ", base);         }         putchar(' ');       }     }        return EXIT_SUCCESS;   }         void displayValueAndBases(unsigned long num, int base, int newbase)   {     void displayValueInBase(unsigned long v, unsigned int b);        displayValueInBase(num, base);     printf(" in base %i is ", base);     displayValueInBase(num, newbase);     printf(" in base %i. ", newbase);   }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote