C ++作为抽象,支持“位”代表两个以上的值之一? [英] Does C++, as an abstraction, support "bits" representing one of more than two values?

查看:98
本文介绍了C ++作为抽象,支持“位”代表两个以上的值之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[C ++ 11:1.7] 以位为单位讲述字节


C ++内存模型中的基本存储单元是字节。字节至少足够大以包含基本执行字符集(2.3)的任何成员和Unicode UTF-8编码形式的8位代码单元,并且由连续的位序列组成,其数目是实现定义。最低有效位称为低位位;最高有效位称为高阶位。 C ++程序可用的存储器由一个或多个连续字节序列组成。每个字节都有一个唯一的地址。


但是,我在标准中找不到定义bit b
$ b

所以说C ++不会对单个位可能表示的值的数量有限制吗?

$ b $

解决方案

3.9.1.7说

p>


类型bool,char,wchar_t和有符号和无符号整型类型
统称为积分类型48)积分的同义词type
是整数类型。整数类型的表示应通过使用纯二进制数字系统来定义
值。[示例:this
国际标准允许整数类型的2的补码,1的补码和
有符号的幅度表示。 - end example]


注释 49 读为


使用二进制数字0
和1的整数的位置表示,其中由连续位表示的值为
additive,开始于1,并乘以2的连续积分
次幂,除了可能对于位置最高的位。
(根据美国国家词典信息
处理系统改编) / p>


[C++11: 1.7] talks about bytes in terms of bits:

The fundamental storage unit in the C++ memory model is the byte. A byte is at least large enough to contain any member of the basic execution character set (2.3) and the eight-bit code units of the Unicode UTF-8 encoding form and is composed of a contiguous sequence of bits, the number of which is implementation-defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order bit. The memory available to a C++ program consists of one or more sequences of contiguous bytes. Every byte has a unique address.

However, I cannot find anywhere in the standard that defines "bit".

So is it true to say that C++ does not place limitations on the number of values that may be represented by a single bit?

Does it allow, say, tri-state bits?

解决方案

3.9.1.7 says

Types bool, char, wchar_t, and the signed and unsigned integer types are collectively called integral types.48) A synonym for integral type is integer type. The representations of integral types shall define values by use of a pure binary numeration system.49) [ Example: this International Standard permits 2’s complement, 1’s complement and signed magnitude representations for integral types. — end example ]"

The note 49 reads

A positional representation for integers that uses the binary digits 0 and 1, in which the values represented by successive bits are additive, begin with 1, and are multiplied by successive integral power of 2, except perhaps for the bit with the highest position. (Adapted from the American National Dictionary for Information Processing Systems.)

这篇关于C ++作为抽象,支持“位”代表两个以上的值之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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