开发者

How did we get this real number in binary?

开发者 https://www.devze.com 2023-04-09 05:03 出处:网络
from this article: the number 5.125 (binary 101.001) why? 101 is 5, but how开发者_StackOverflow中文版 are decimal places converted?

from this article:

the number 5.125 (binary 101.001) why? 101 is 5 , but how开发者_StackOverflow中文版 are decimal places converted?

Also from that article - a bias is added to the actual exponent e.

What is bias? What is the purpose of it?


Why b101.001 = 5.125?

That's just how digits after the binary point work. They're like the digits after the decimal point in base10 (commonly known as the "decimals").

b10 = 2^1
b1 = 2^0
b0.1 = 2^-1
b0.01 = 2^-2
b0.001 = 2^-3 = 0.125

This representation is called fixed-point. More information here.


What is exponent bias?

Bias is a part of the specification for representing floating-point numbers in binary (see IEEE 754). It's the number you add to the exponent to convert it from a -limit to +limit range to a 0 to +2*limit range. This makes the computer able to store the number with the unsigned interpretation.

Why exponent bias?

The reason for using the exponent bias is that it'll allow the computer to use an unsigned system instead of the two's complement. This makes floating-point comparison easier.


See the Floating-Point guide for a detailed explanation of how binary fractions work.

What is bias? What is the purpose of it?

A biased exponent is used because it allows floating-point numbers to compared for value exactly like integer numbers, i.e. if a bit pattern A is greater than a bit pattern B when interpreted as integer, the same is always true if you interpret the patters as floating-point numbers.


Just the same way: Each "1"-digit contributes 2^d, where d is the place of the digit. The unit digit is in place 0, the place counts up to the left and down to the right, so the place right of the point is -1. So 0.001 is 2^-3, or 1/8, or 0.125.


The purpose of the bias in the exponent in IEEE754 floating point representations is so that you do not require any extra logic to determine the sign of the exponent, and it has the additional advantage that the lexicographic ordering of the binary representation equals the value ordering (at least for a fixed sign): So 0x00000000, which is 0.0, is followed by 0x00000001, which is the smallest positive (though denormal) float. It's exponent is the smallest (negative) exponent, thanks to the bias.


1 * 2^2  = 4
0 * 2^1  = 0
1 * 2^0  = 1
.
0 * 2^-1 = 0
0 * 2^-2 = 0
1 * 2^-3 = 0.125
----------------
101.001  = 5.125

The exponent on the base continues decrementing each digit past the decimal point. In base two that means that the first digit is worth 1/2 = .5, the second is 1/4 = .25 and the third is 1/8 = 0.125.

It works the same way as base 10: The first digit is 1/10 = 0.1, the second is 1/100 = 0.01 etc...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号