Jump to content

question about floating point number

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
mike221

mike221

    Newbie

  • Members
  • PipPip
  • 11 posts
Hi. I want to present number -6.25 as a floating point number ( 32 bit presentation )

My solution is ( because number is negative; first 1 bits and then .25 )

1111 1111 1111 1111 0000 0110 0001 1001

4 2 16 8 1
---- -----------
6 25

Is this the right way?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It depends on what specification you are trying to conform to (IEEE?).
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
mike221

mike221

    Newbie

  • Members
  • PipPip
  • 11 posts
Hi. Yes; IEEE. I think my solution is right, but I am not 100 % sure.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I don't think the bits for your exponent are correct, based on what I'm seeing here.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
mike221

mike221

    Newbie

  • Members
  • PipPip
  • 11 posts
I give up, too difficult...Oh my god, can someone please ( ??? ) tell what would be right;

-8.35

and my solution was
1111 1111 1111 1111 0000 0110 0001 1001

but exponents are wrong. IEEE

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Let's break this up:
You have:
-8.35 = - (100.010101000...)
sign: 1 --> negative
exponent: 111 1111 1 --> exponent of 128!
fraction: 111 1111 0000 0110 0001 1001 --> binary base value of 1.111 1111 0000 0110 0001 1001.
Thus, my assertion that your result is incorrect.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
mike221

mike221

    Newbie

  • Members
  • PipPip
  • 11 posts
THANKS!

Yeah, I changed the negative number to -8.35 and so that is;

binary base value of 1.111 1111 0000 0110 0001 1001 and in so 32 bit it is;


1111 1111 1.111 1111 0000 0110 0001 1001

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
My point is, your exponent should NOT be 128! It's actually 2.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#9
mike221

mike221

    Newbie

  • Members
  • PipPip
  • 11 posts
Ah, so -8.35 is;

0000 0010 1.111 1111 0000 0110 0001 1001.


now exponent isn't 128. But it is 2. Still right?...

#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You have several bits you have to combine:
(x) - sign bit
(xxxx xxxx) - exponent bits with 127 added to the value represented
(xxxx xxxx xxxx xxxx xxxx xxx) - digits after the decimal point after you have shifted the digits so only the lead 1 is to the left of the decimal point

- means the sign bit is 1
exponent 2 means you have to encode 129 for the exponent bits
for the fraction, convert 8.35 to binary, and copy all the bits EXCEPT the leading 1!
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog