Question

implement two functions in c++ format 1.Convert decimal number to floating point representation (hexa decimal) 2.Convert...

implement two functions in c++ format

1.Convert decimal number to floating point representation (hexa decimal)

2.Convert floating point representation (hexa decimal) to decimal number

Note: We only care about the floating point number in IEEE754 Encoding table below (i.e., exponent 1 – 254).  

-----------------------------------------------------------------------------------------------------------------

void from_decimal_to_floating(){
    char number[10];
    float decimal = 0;
    cout << "Input decimal to convert a hexa decimal number (e.g., 0.4375): ";
    cin >> decimal;
    //write the code here



   
    //end of code 
    cout << decimal << "'s floating point hexa decimal : " << number; 
    cout << endl << "[format]: 0.4375's floating point hexa decimal : 3EE00000" << endl << endl;
} 

void from_floating_to_decimal(){
    char number[10];
    float decimal = 0;
    cout << "Input hexa decimal to convert a decimal number (e.g., 3EE00000): ";
    cin >> number;
    //write the code here



   
    //end of code 
    cout << number << "'s decimal : " << decimal ; 
    cout << endl << "[format]: 3EE00000's decimal : 0.4375" << endl << endl;
} 
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Converting decimal to hexadecimal value:
void from_decimal_to_floating(){
    int num, temp, i = 1, j, r;
    char number[10];
    float decimal = 0;
    cout << "Input decimal to convert a hexa decimal number (e.g., 0.4375): ";
    cin >> decimal;
    
    temp = decimal;
    while (temp != 0)
    {
        r = temp % 16;
        if (r < 10)
            number[i++] = r + 48;
        else
            number[i++] = r + 55;
        temp = temp / 16;
    }
    cout << decimal << "'s floating point hexa decimal : " << " is : ";
    for (j = i; j > 0; j--)
        cout << number[j];
} 

Convert Hexadecimal value to decimal :

void from_floating_to_decimal(){
    char number[10];
    float decimal = 0;
    int i, r, len, hex = 0;
    cout << "Input hexa decimal to convert a decimal number : ";
    cin >> number;
    //write the code here
    len = strlen(number);
    for (i = 0; number[i] != '\0'; i++)
    {
        len--;
        if(number[i] >= '0' && number[i] <= '9')
            r = number[i] - 48;
        else if(number[i] >= 'a' && number[i] <= 'f')
                r = number[i] - 87;
             else if(number[i] >= 'A' && number[i] <= 'F')
                    r = number[i] - 55;
        decimal += r * pow(16,len);
    } 
    cout << number << "'s decimal : " << decimal ; 
} 

Add a comment
Know the answer?
Add Answer to:
implement two functions in c++ format 1.Convert decimal number to floating point representation (hexa decimal) 2.Convert...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Convert the following from the floating point representation to a decimal (base 10) representation using the...

    Convert the following from the floating point representation to a decimal (base 10) representation using the format in 5.19 of your text: 10010111010010100011011010101011

  • Consider a 9-bit floating-point representation based on the IEEE floating-point format, with one sign bit, four...

    Consider a 9-bit floating-point representation based on the IEEE floating-point format, with one sign bit, four exponent bits (k = 4), and four fraction bits (n = 4). The exponent bias is 24-1-1-7. The table that follows enumerates some of the values for this 9-bit floating-point representation. Fill in the blank table entries using the following directions: e : The value represented by considering the exponent field to be an unsigned integer (as a decimal value) E: The value of...

  • 6. The exponent in IEEE format floating point numbers are not represented in 2's complement format....

    6. The exponent in IEEE format floating point numbers are not represented in 2's complement format. Why not? What number is indicated if the value stored in the exponent is zero? What exponent and fraction are used to represent "not-a-number"? 7. This question deals with two numbers in IEEE format (A - 0x3F400000, B 0x3DB00000 (a) Calculate A+B using the floating-point addition procedure discussed in class. Determine the single precision result and express your answer in IEEE floating-point format. Convert...

  • . 2.1 a.  Find the 16-bit 2’s complementary binary representation for the decimal number 1987. b.   Find...

    . 2.1 a.  Find the 16-bit 2’s complementary binary representation for the decimal number 1987. b.   Find the 16-bit 2’s complementary binary representation for the decimal number −1987. What are the 16-bit 1’s and 2’s complements of the following binary numbers? a.   10000 b.   100111100001001 Convert the decimal number 19557 to floating point. Use the format SEEMMMM. All digits are decimal. The exponent is stored excess-40 (not excess-50). The implied decimal point is at the beginning of the mantissa. The sign...

  • 2.1 a. Find the 16-bit 2’s complementary binary representation for the decimal number 1987. b. Find...

    2.1 a. Find the 16-bit 2’s complementary binary representation for the decimal number 1987. b. Find the 16-bit 2’s complementary binary representation for the decimal number −1987. What are the 16-bit 1’s and 2’s complements of the following binary numbers? c. 10000 d. 100111100001001 Convert the decimal number 19557 to floating point. Use the format SEEMMMM. All digits are decimal. The exponent is stored excess-40 (not excess-50). The implied decimal point is at the beginning of the mantissa. The sign...

  • Assume a 10-bit floating point representation format where the Exponent Field has 4 bits

    Assume a 10-bit floating point representation format where the Exponent Field has 4 bits and the Fraction Field has 6 bits and the sign bit field uses 1 bit  S      Exponent Field: 4 bits       Fraction Fleld: 5 bits a) What is the representation of -8.80158 × 10-2 in this Format - assume bias =2M-1-1=24-1-1=7 (where N= number of exponent field bits) for normalized representation 1 -bias =-6 : for denormalized representationb) What is the range of representation for...

  • [10pts] Convert Binary to Decimal Floating Point. What decimal number is represented by this single precision...

    [10pts] Convert Binary to Decimal Floating Point. What decimal number is represented by this single precision float? 0xCOB40000 4.

  • Assume the following representation for a floating point number 1 sign bit

     Assume the following representation for a floating point number 1 sign bit, 4 bits exponent, 5 bits for the significand, and a bias of 7 for the exponent (there is no implied 1 as in IEEE). a) What is the largest number (in binary) that can be stored? Estimate it in decimal. b) What is the smallest positive number( closest to 0 ) that can be stored in binary? Estimate it in decimal.c) Describe the steps for adding two floating point numbers. d)...

  • please explain steps!! Convert the boy binary floating point numbers below to decimal notation forseti 8...

    please explain steps!! Convert the boy binary floating point numbers below to decimal notation forseti 8 bits: SEEEEEFF and the bias is 7, where S-sign, E-Exponent acts on bits) 10 pt. / 5 pts es convert from 8 bit floating point binary format convert to: decimal +/-n.nn DS EEE (FFC - 0100 1.100 = -1,5 426 6 14.05 Yoryal = 15 +0111 1140=125 10110100 00111110 me floating point

  • If we use the IEEE standard floating-point single-precision representation (1 sign bit, 8 bit exponent bits...

    If we use the IEEE standard floating-point single-precision representation (1 sign bit, 8 bit exponent bits using excess-127 representation, 23 significand bits with implied bit), then which of the following hexadecimal number is equal to the decimal value 3.875? C0780000 40007800 Oo 40780000 40A80010 The binary string 01001001110000 is a floating-point number expressed using a simplified 14-bit floating-point representation format (1 sign bit, 5 exponent bits using excess-15 representation, and 8 significand bits with no implied bit). What is its...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT