gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:31:05 25 4
gpt4 key购买 nike

为什么一个字节的范围只能从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com