更具体地说,具有n位整数(包括一位符号)和n位小数的2n位二进制数。
什么是我们可以代表的最小和最大的积极的非零数字?
我知道如何处理整数,但不确定分数。
More specifically a binary number in 2n bits with n bits of integer (including one bit of sign) and n bits of fraction.
What would be the smallest and largest, positive, non-zero number we could represent?
I know how to deal with integer but not sure about the fractions.
最满意答案
一个典型的二进制定点表示是一个以2的常数幂定标的整数,所涉及的因素是
整数的范围和 定点类型的规模。给定一个带有符号位和2n-1位的二进制补码整数,正数的范围是[1..(2^(2n-1))-1] ,标度是2^-n 。 所以最小和最大正定点值是[1*2^-n..((2^(2n-1))-1)*2^-n] 。
例如, C的int16_t类型有15个数字,因此它的范围是[1..(2^15)-1]或[1..32767] 。 在这里, n是8使得比例2^-8或1/256 。 因此缩放范围是[1/256..32767/256]或[0.00390625..127.99609375] 。 您可以使用此C ++程序使用CNL来计算n不同值的范围。
A typical binary fixed-point representation is an integer scaled by a constant power of two so the factors involved are
the range of the integer and the scale of the fixed-point type.Given a two's complement integer with a sign bit and 2n-1 digits, the range of positive numbers is [1..(2^(2n-1))-1] and the scale is 2^-n. So the minimum and maximum positive fixed-point values are [1*2^-n..((2^(2n-1))-1)*2^-n].
For example, C's int16_t type has 15 digits so its range is [1..(2^15)-1] or [1..32767]. Here, n is 8 making the scale 2^-8 or 1/256. So the scaled range is [1/256..32767/256] or [0.00390625..127.99609375]. You can use this C++ program to calculate the range for different values of n using CNL.
更多推荐
发布评论