binary - 为什么一个字节只有 0 到 255?

标签 binary byte

为什么一个字节的范围只能从 0 到 255?

最佳答案

严格来说,术语“字节”实际上可以指具有 256 个值以外的单元。只是那是几乎通用的尺寸。来自 Wikipedia :

Historically, a byte was the number of bits used to encode a single character of text in a computer and it is for this reason the basic addressable element in many computer architectures.

The size of the byte has historically been hardware dependent and no definitive standards exist that mandate the size. The de facto standard of eight bits is a convenient power of two permitting the values 0 through 255 for one byte. Many types of applications use variables representable in eight or fewer bits, and processor designers optimize for this common usage. The popularity of major commercial computing architectures have aided in the ubiquitous acceptance of the 8-bit size. The term octet was defined to explicitly denote a sequence of 8 bits because of the ambiguity associated with the term byte.



具有讽刺意味的是,如今“单个字符”的大小在大多数情况下不再考虑单个字节......最常见的是,“字符”的概念与 Unicode 相关联,其中字符可以用许多不同的格式,但通常是 16 位或 32 位。

对于使用 UCS-4/UTF-32(Unicode 的直接 32 位表示)的系统将 32 位指定为一个字节会很有趣。造成的困惑将是壮观的。

但是,假设我们将“byte”作为“octet”的同义词,则有八个独立的bits ,每个都可以是开或关,真或假,1 或 0,但是你想怎么想。这导致了 256 个可能的值,通常编号为 0 到 255。(但情况并非总是如此。例如,Java 的设计者不幸决定将字节视为 -128 到 127 范围内的有符号整数。)

关于binary - 为什么一个字节只有 0 到 255?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4986486/

相关文章:

python - 使用python从二进制文件中读取数字数据

c++ - std::bitset 的二进制序列化

c++ - 将二进制数据读入 std::string C++

c++ - C++中的通用二进制搜索

Python3 破坏有效的 Python2 代码 : How can I send a series of bytes in a buffer in a socket in Python?

java - 这个 Java ByteBuffer 的行为有解释吗?

java - 为什么java没有字节类型后缀?

Java - 无法编辑字节数组内容?

java - 特定整数在运行时需要多少字节?

php - 任何二进制文件都可以在php中转换为图像吗