为什么无符号 n 位整数的最大值是 2ⁿ-1 而不是 2ⁿ? [英] Why is the maximum value of an unsigned n-bit integer 2ⁿ-1 and not 2ⁿ?

查看:20
本文介绍了为什么无符号 n 位整数的最大值是 2ⁿ-1 而不是 2ⁿ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

n 位整数的最大值为 2n-1.为什么我们有负1"?为什么最大值不只是 2n?

The maximum value of an n-bit integer is 2n-1. Why do we have the "minus 1"? Why isn't the maximum just 2n?

推荐答案

-1是因为整数从0开始,但我们的计数从1开始.

The -1 is because integers start at 0, but our counting starts at 1.

因此,2^32-1 是 32 位无符号整数(32 个二进制位)的最大值.2^32可能值的数量.

So, 2^32-1 is the maximum value for a 32-bit unsigned integer (32 binary digits). 2^32 is the number of possible values.

为了简化原因,请查看小数.10^2-1 是 2 位十进制数 (99) 的最大值.因为我们直观的人工计数从 1 开始,但整数是从 0 开始的,所以 10^2 是值的数量 (100).

To simplify why, look at decimal. 10^2-1 is the maximum value of a 2-digit decimal number (99). Because our intuitive human counting starts at 1, but integers are 0-based, 10^2 is the number of values (100).

这篇关于为什么无符号 n 位整数的最大值是 2ⁿ-1 而不是 2ⁿ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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