为什么一个字节只有0到255? [英] Why does a byte only have 0 to 255?

查看:826
本文介绍了为什么一个字节只有0到255?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why does a byte only range from 0 to 255?

推荐答案

严格来说,术语字节"实际上可以指代具有256个值以外的值的单位.只是这是几乎通用的大小.来自 Wikipedia :

Strictly speaking, the term "byte" can actually refer to a unit with other than 256 values. It's just that that's the almost universal size. From 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.

字节的大小在历史上一直 取决于硬件,没有 存在明确的标准, 规定大小.事实 八位标准很方便 2的幂次方,允许值0 255表示一个字节.多种类型 的应用程序使用变量 可以用八位或更少的位表示 处理器设计人员针对 这种常见的用法.的普及 主要商业计算 架构有助于 普遍接受8位 尺寸.八位位组一词的定义是 明确表示一个8位的序列 因为模棱两可 带有字节一词.

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位.

Ironically, these days the size of "a single character" is no longer consider a single byte in most cases... most commonly, the idea of a "character" is associated with Unicode, where characters can be represented in a number of different formats, but are typically either 16 bits or 32.

对于使用UCS-4/UTF-32(Unicode的直接32位表示形式)将32位指定为字节的系统而言,这将很有趣.造成的混乱将是惊人的.

It would be amusing for a system which used UCS-4/UTF-32 (the direct 32-bit representation of Unicode) to designate 32 bits as a byte. The confusion caused would be spectacular.

但是,假设我们将字节"与八位字节"同义,则有八个独立的 ,每个值都可以打开或关闭,对或错,1或0,但是您应该考虑一下.这将导致256个可能的值,通常将其编号为0到255.(尽管并非总是如此.例如,Java的设计人员不幸地决定将字节视为-128范围内的 signed 整数.到127.)

However, assuming we take "byte" as synonymous with "octet", there are eight independent bits, each of which can be either on or off, true or false, 1 or 0, however you wish to think of it. That leads to 256 possible values, which are typically numbered 0 to 255. (That's not always the case though. For example, the designers of Java unfortunately decided to treat bytes as signed integers in the range -128 to 127.)

这篇关于为什么一个字节只有0到255?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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