LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-05-2011, 03:54 AM   #1
BlueSpirit
Member
 
Registered: Jun 2006
Distribution: Slackware
Posts: 144

Rep: Reputation: 15
IEEE floating point format


Hi,

I'm reading a book on assembly, and it talks a bit about the IEEE floating point format.

Quote:
To summarize, the following steps are used to convert a decimal number to
IEEE single format:
1. The leading bit of the floating point format is 0 for a positive number
and 1 for a negative number.
2. Write the unsigned number in binary.
3. Write the binary number in binary scientific notation f23.f22 ... f0 2^e,
where f23 = 1. There are 24 fraction bits, but it is not necessary to write
trailing 0's.
4. Add a bias of 127 to the exponent e. This sum, in binary form, is the
next 8 bits of the answer, following the sign bit. (Adding a bias is an
alternative to storing the exponent as a signed number.)
5. The fraction bits f22f21 ... f0 form the last 23 bits of the floating point
number. The leading bit f23 (which is always 1) is dropped.
Can anyone explain me what he means by "adding a bias of 127 is an alternative to storing the exponent as a signed number"??

Thanks!

BlueSpirit

Last edited by BlueSpirit; 06-06-2011 at 02:15 AM.
 
Old 06-05-2011, 07:51 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by BlueSpirit View Post
Can anyone explain me what he means by "adding a bias of 127
Did you understand step 3?

(I also don't know how to show a superscript in forum text). I hope you understood that where you wrote 2e in step 3, the original you copied had somehow indicated it meant 2 to the power e.

After doing step 3 (assuming you understood it), you are supposed to add 127 to e. For numbers that can be represented in this format, the result of that addition will be a number in the range 1..255.

For example, say I started with 0.140625, which happens to be 9/64. In binary that is .001001 which is 1.001 * 2 to the negative 3.

So we add 127 to negative 3, getting 124 (which conveniently is in the range 1..255).

So the top bit is 0 indicating positive. The next 8 bits are 01111100 indicating the exponent of 124. The next three bits are 001 from the fractional part of 1.001

Quote:
" is an alternative to storing the exponent as a signed number"??"
The basic requirement was to store that exponent (in my example negative 3) and to reserve one of the 256 possible values of the 8 bit field in which that exponent is stored. One could have designed a floating point format in which a signed eight bit number was used for the exponent. A signed 8 bit number holds value -128 through +127. One might reserve -128, and allow exponents -127 through +127.

An unsigned 8 bit number holds values 0 through 255. By adding 127 and reserving the value 0, the actual format supports original exponents -126 through +128, which is only very slightly more useful than supporting -127 through +127. There were more important reasons (for the designer of the format) for adding 127 and then using an unsigned field, but those aren't as easy to explain. You should just need to understand that this format was designed this way.

Last edited by johnsfine; 06-05-2011 at 08:08 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
floating point exception? birjodh Linux - General 1 06-10-2007 03:11 AM
Floating point exception ramesh6056 Linux - Software 1 05-29-2007 01:14 AM
IEEE 754 floating point numbers dmail Programming 3 02-05-2006 05:10 AM
Floating Point in kernel 2.4.28 lucs Slackware 1 10-19-2005 08:33 AM
Floating point exception hemk76 Linux - Software 1 05-06-2005 11:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration