为什么阶码要有偏置常数?

Why do we need biased exponent ?

Introduction:

The following algorithm (for an n-bit two’s complement architecture) sets the result register R to −1 if A < B, to +1 if A > B, and to 0 if A and B are equal:

// reversed comparison of the sign bit

if A(n-1) == 0 and B(n-1) == 1 then
    return +1
else if A(n-1) == 1 and B(n-1) == 0 then
    return -1
end
 
// comparison of remaining bits

for i = n-2...0 do
    if A(i) == 0 and B(i) == 1 then
        return -1
    else if A(i) == 1 and B(i) == 0 then
        return +1 
    end
end
 
return 0

However, Unsigned binary numbers can be ordered by a simple lexicographic ordering, where the bit value 0 is defined as less than the bit value 1. So the best way is to transform the data to unsigned type by adopting offset.

Usually signed integers are stored as two’s complement. However, exponent in IEEE-754 floating point standard is stored as offset binary. It also has many other names, like biased exponent or offset-k, where k denotes an offset. If you google around on how to represent a number using this scheme, you’ll find that you just need to calculate an offset (bias), and then add it to the number you’re trying to store. The resulting number is what actually gets stored. Then convert to binary, if necessary.

To demonstrate the steps let’s see how the number 3 can be stored in 4 bits:

  1. Find the offset using the formula mentioned in IEEE-754 standard:
    K = 2 n − 1 − 1 K=2^{n-1}-1 K=2n11

where n is the number of bits. So the offset for 4 bits is 7.

  1. Add offset to the original number: 3 + 7 = 10. The resulting number 10 is how the number 3 is stored under the offset binary scheme. Since we used decimal system to get resulting number 10, we need to convert it to binary:
    1 0 10 = 101 0 2 10_{10}=1010_2 1010=10102

Defining offset

Suppose we have only 4 bits to store numbers. How many different numbers can we represent with 4 bits? It’s easy to calculate:
2 4 = 16 2^4=16 24=16
The calculation shows us that we can store 16 different numbers in 4 bits. The question is what those numbers might be. Suppose we’re interested in storing only non-negative integers. Then, the range is:

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值