• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to calculate binaries with a decimal in them (homework help)

Status
Not open for further replies.

kia75

Senior member
Ok, a friend of mine is doing a homework assignment at the moment converting ieee 754 floating point number to a decimal number.

We seem to be doing ok until we get to a binary number with a decimal place. I've never done this before (yeah, laugh at me). How do you convert binary numbers with decimals in them?

The number we're supposed to convert to decimal is:

0 10000011 01110110000000000000000

We have the following formula: sign * 2exponent * mantissa

We've gotten 4 for the exponent, but we have no idea how to convert 1.0111011 into decimal.

Any help would be greatly appreciated.

Thanks.
 
Have you read the "hitch hikers guide to the galaxy"?

It has the "Dont panic" on the back in nice friendly letters.
 
1.0111011

1 = 1*2^0 = 1
.
0 = 0*2^-1 = 0
1 = 1*2^-2 = .25
1 = 1*2^-3 = .125
1 = 1*2^-4 = .0625
0 = 0*2^-5 = 0
1 = 1*2^-6 = .015625
1 = 1*2^-7 = .007813

Now add it all up.

1 + 0 + .25 + .125 + .0625 + 0 + .015625 + .007813 = 1.4609375

It's the exact same principle as base 10. When you have a number like 28.1498, that is really the same as...

2 = 2*10^1 = 20
8 = 8*10^0 = 8
.
1 = 1*10^-1 = .1
4 = 4*10^-2 = .04
9 = 9*10^-3 = .009
8 = 8*10^-4 = .0008

It's just easier to visualize in base 10 since you inherently know how to manipulate numbers in those terms.

The algorithm is as follows:

N = number system, e.g. 16, 10, 2, etc.
i = position in number sequence relative to the radix point.

A(i) * N ^ i

Consider another example:

Convert 706.14 base 8 to base 10. (There is an easier way to do this, but for the sake of argument, we will use the algorithm shown above).

7: i = 2 position, 7 * 8 ^ 2 = 448
0: i = 1 position, 0 * 8 ^ 1 = 0
6: i = 0 position, 6 * 8 ^ 0 = 6
1: i =-1 position, 1 * 8 ^ -1 = .125
4: i =-2 position, 4 * 8 ^ -2 = .0625

Add it up and you get 454.1875 base 10.

Converting between other numbers systems (i.e. not just converting base X to base 10) is straightforward if you understand how to count in any base. It is different than what I showed above.
 
Last edited:
Status
Not open for further replies.
Back
Top