什么是最大/最小定点数可以用2n位表示?(What is the largest/smallest fixed point number than can be represented in 2n b

编程入门 行业动态 更新时间:2024-10-13 16:21:44
什么是最大/最小定点数可以用2n位表示?(What is the largest/smallest fixed point number than can be represented in 2n bits?)

更具体地说,具有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.

更多推荐

本文发布于:2023-07-06 07:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以用   点数   最小   largest   smallest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!