多少个值可以被重新使用n比特psented $ P $? [英] How many values can be represented with n bits?

查看:142
本文介绍了多少个值可以被重新使用n比特psented $ P $?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果 N = 9 ,那么有多少不同的值可以重新$ P $ 9二进制数字psented(位)?

For example, if n=9, then how many different values can be represented in 9 binary digits (bits)?

我的想法是,那些每9位的,如果我设置为1,我会次数最多的可能是那些9位可以重新present。因此,最高值为 111111111 等于十进制511 。我的结论是,因此,二进制的9位可以重新present 511不同的值。

My thinking is that if I set each of those 9 bits to 1, I will make the highest number possible that those 9 digits are able to represent. Therefore, the highest value is 1 1111 1111 which equals 511 in decimal. I conclude that, therefore, 9 digits of binary can represent 511 different values.

是我的思维过程是否正确?如果没有,可能有人善意解释我缺少的是什么?我怎么可以把它推广到 N 位?

Is my thought process correct? If not, could someone kindly explain what I'm missing? How can I generalize it to n bits?

推荐答案

2 9 = 512的值,因为这是你可以有多少的0和1的组合都有。

29 = 512 values, because that's how many combinations of zeroes and ones you can have.

什么这些值重新present但是取决于你所使用的系统上。如果它是一个无符号整数,你将有:

What those values represent however will depend on the system you are using. If it's an unsigned integer, you will have:

000000000 = 0 (min)
000000001 = 1
...
111111110 = 510
111111111 = 511 (max)

二补时,其通常用于重新二进制present整数,你会有:

In two's complement, which is commonly used to represent integers in binary, you'll have:

000000000 = 0
000000001 = 1
...
011111110 = 254
011111111 = 255 (max)
100000000 = -256 (min) <- yay integer overflow
100000001 = -255
...
111111110 = -2
111111111 = -1

在一般情况下,用的 K 的位可以重新present 2 K 值。它们的范围将取决于你所使用的系统上:

In general, with k bits you can represent 2k values. Their range will depend on the system you are using:

无符号:0〜2 K -1结果
  签名:-2 K-1 2 K-1 1

Unsigned: 0 to 2k-1
Signed: -2k-1 to 2k-1-1

这篇关于多少个值可以被重新使用n比特psented $ P $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆