Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 575119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:54:13+00:00 2026-05-13T13:54:13+00:00

Can someone look over my program and tell me if i am doing it

  • 0

Can someone look over my program and tell me if i am doing it correctly?

I am accepting user input in the form of 8 hexadecimal digits. I want to interpret those 8 digits as an IEEE 754 32-bit floating point number and will print out information about that number.

here is my output:

IEEE 754 32-bit floating point

byte order: little-endian

>7fffffff

0x7FFFFFFF
signBit 0, expbits 255, fractbits 0x007FFFFF
normalized:   exp = 128
SNaN

>40000000

0x40000000
signBit 0, expbits 128, fractbits 0x00000000
normalized:   exp = 1

>0

0x00000000
signBit 0, expbits 0, fractbits 0x00000000
+zero

here is the code..

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{


int HexNumber;
int tru_exp =0;
int stored_exp;
int negative;
int exponent;
int mantissa;

printf("IEEE 754 32-bit floating point");


int a = 0x12345678;
unsigned char *c = (unsigned char*)(&a);
if (*c == 0x78)
{
    printf("\nbyte order: little-endian\n");
}
else
{
    printf("\nbyte order: big-endian\n");
}

do{

printf("\n>");
scanf("%x", &HexNumber);

    printf("\n0x%08X",HexNumber);

negative = !!(HexNumber & 0x80000000);
exponent = (HexNumber & 0x7f800000) >> 23;
mantissa = (HexNumber & 0x007FFFFF);


printf("\nsignBit %d, ", negative);
printf("expbits %d, ", exponent);
printf("fractbits 0x%08X", mantissa);
//  "%#010x, ", mantissa);

if(exponent == 0)
{
    if(mantissa != 0)
    {
        printf("\ndenormalized  ");
    }
}
else{
    printf("\nnormalized:   ");
    tru_exp = exponent - 127;
    printf("exp = %d", tru_exp);
}

if(exponent == 0 && mantissa == 0 && negative == 1)
{

    printf("\n-zero");

}

if(exponent ==0 && mantissa == 0 && negative == 0)
{
 printf("\n+zero");
}



if(exponent == 255 && mantissa != 0 && negative == 1)
{

    printf("\nQNaN");

}

   if(exponent == 255 && mantissa != 0 && negative == 0)
{

    printf("\nSNaN");

}

if(exponent == 0xff && mantissa == 0 && negative == 1)
{
    printf("\n-infinity");
}

if(exponent == 0xff && mantissa == 0 && negative == 0)
{
    printf("\n+infinity");
}


    printf("\n");
}while(HexNumber != 0);



return 0;
  }

I dont think the de normalized is right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:54:13+00:00Added an answer on May 13, 2026 at 1:54 pm

    Generally, you’re pretty close. Some comments:

    • 0x7fffffff is a quiet NaN, not a signaling NaN. The signbit does not determine whether or not a NaN is quiet; rather it is the leading bit of the significand (the preferred term for what you call “mantissa”) field. 0xffbfffff is a signaling NaN, for example.

    Edit: interjay correctly points out that this encoding isn’t actually required by IEEE-754; a platform is free to use a different encoding for differentiating quiet and signaling NaNs. However, it is recommended by the standard:

    A quiet NaN bit string should be
    encoded with the first bit of the
    trailing significand field T being 1.
    A signaling NaN bit string should be
    encoded with the first bit of the
    trailing significand field being 0.

    • Infinities and NaNs usually aren’t called “normal numbers” in the IEEE-754 terminology.

    • Your condition for calling a number “denormal” is correct.

    • For normal numbers, it would be nice to add the implicit leading bit when you report the significand. I personally would probably print them out in the C99 hex notation: 0x40000000 has a significand (once you add the implicit bit) of 0x800000 and an exponent of 1, so becomes 0x1.000000p1.

    • I’m sure some aging PDP-11 hacker will give you a hard time about “big endian” and “little endian” not being the only two possibilities.

    Edit Ok, example of checking for qNaN on platforms that use IEEE-754’s recommended encoding:

    if (exponent == 0xff && mantissa & 0x00400000) printf("\nqNaN");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain to me the advantages of using an IOC container over simply
Can someone show me how to implement a recursive lambda expression to traverse a
Can someone explain the mechanics of a jump table and why is would be
Can someone give an example of a good time to actually use unsafe and
Can someone describe what a symbol table is within the context of C and
Can someone explain this result to me. The first test succeeds but the second
Can someone explain what exactly the string 0 but true means in Perl? As
Can someone explain what are the benefits of using the @import syntax comparing to
Can someone explain how to use if-then statements and for loops in Makefiles? I
Can someone explain why how the result for the following unpack is computed? aaa.unpack('h2H2')

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.