Solved

16 bit floating point binary

Posted on 2004-04-13
8
588 Views
Last Modified: 2010-04-15
i have to write a c program to perform some arithmetic operations on 16 bit floating point binary numbers.

the format is as follows:

SBBBBBMMMMMMMMMM

S= sign bit
B= biased exponent (bias = 16)
M= normalized matissa

i have to add two of them first and then substract. i dont even understand what is B and M.

please help me.

thanks a lot,
tony.
0
Comment
Question by:backwaters
  • 4
  • 2
8 Comments
 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 25 total points
ID: 10813697
Hi backwaters,

A floating point number consists of a normalized mantissa and an exponent, so that

M * 10 ^ E

is your number. A mantissa is normalized if it has only one digit in the rand 1...9 before the decimal point.

Have a look at

http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html

This also shows the "biasing" of the exponent. In the simplest case, the exponent biasing simply means it is a signed integer (like with IEEE 32 bit floats). But you can shift the exponent range either way, depending on your needs (if you need rather small or big numbers).

Cheers,
Stefan
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10813728
backwaters,
> BBBBB
Here the biasing is the very same as in the 32 bit IEEEs (look for the "- 127 = "). Basically, the leftmost bit is the sign of your exponent.

Stefan
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10813749
As this appears to be homework, this is all I can do so far for you.

Good Luck!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 45

Accepted Solution

by:
Kdo earned 75 total points
ID: 10813776
Hi backwaters,

What you've been asked to do is code the floating point operations for a 16-bit register/word.  (Obviously homework.)

I assume that your code will perform the basic math functions (add, subtract, multiply, and divide).  Add and subtract can be coded as one function, multiply and divide are unique.

A 16 bit integer looks like this:

0000000000000001

Exponential notation says that 1E+0 is the representation for 1 in base 10.  1E+6 is the exponential notation for a million, 1E+100 is a google.

If you consider the exponent to be in base 2 (binary) instead of base 10, the floating point arithmetic makes more sense.  1E+0 is 1, 1E+1 is 2, 1E+2 is 4, etc...  This simply says that shifting a 1 left by the number of bits in the exponent gives the number.

That's what your floating point format says, except that the exponent is biased.  Biasing the exponent means that the exponent can never be negative.  You've got a 5 bit exponent, so whatever the true value is, simply add 10000(2) to it to get the biased value.

Confused?  Don't be.  Let's convert the integer 1 to a floating point 1.  The way to do that is to insert the exponent into the 16 bit value in the correct location.

The exponent is 0 because we don't need to shift the 1.  A 1 is a 1 and we're starting with an integer 1.  We add the bias to it and the exponent becomes 10000(2) + 0 = 10000(2).  Inserting this value into the word gives us

0100000000000001

This is an un-normalized 1.  To normalize the value, we need to left shift the mantissa until the top bit is a 1. For every bit that we shift the mantissa, we need to adjust the exponent by decrementing it 1.

0011110000000010
0011100000000100
0011010000001000
0011000000010000
0010110000100000
0010100001000000
0010010010000000
0010000100000000
0001111000000000

There you have it -- a "normalized" 1 in the floating point format that you've described.

This is the foundation.  There's a lot more that you'll have to know/do to actually build the functions.

Good Luck!
Kent
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10813906
Kdo,
Good explanation!

Stefan
0
 
LVL 45

Expert Comment

by:Kdo
ID: 10814052
Hi Stefan,

I was interrupted so the post took longer to assemble than normal.  When I started typing there were no other replies....

:)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How do I test for current date? 9 90
FILE closing 11 68
Grammars for C C++ and java 1 108
valid enum? 6 67
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now