无符号窄字符类型数字表示 [英] Unsigned narrow character type number representation

查看:138
本文介绍了无符号窄字符类型数字表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

N3797 :: 3.9.1 / 1 [basic.fundamental]


对于无符号窄字符类型,
值表示中的所有可能的位模式都表示数字。

For unsigned narrow character types, all possible bit patterns of the value representation represent numbers.

这对我来说有点不清楚。对于窄字符类型,我们有以下范围:

That's a bit unclear for me. We have the following ranges for narrow character types:

unsigned char := 0 -- 255
signed char : = -128 -- 127

对于 unsgined char signed char 对象,我们有一对一映射从这些对象表示中的位到它们可以表示的积分值。标准说 N3797 :: 3.9.1 / 1 [basic.fundamental]

For both unsgined char and signed char objects we have one-to-one mapping from the set of bits in these object representation to the integral value they could represent. The Standard says N3797::3.9.1/1 [basic.fundamental]


These requirements do not hold for other types.

为什么我引用的要求不适用于签名的类型可以使用以下三种表示形式之一:二进制补码,一个补码,一个有符号的char 类型?

Why the requirement I cited doesn't hold say for signed char type?

推荐答案

,或符号量。最后两个有一个位模式(零否定),它不代表一个数字。

Signed types can use one of three representations: two's complement, one's complement, or sign-magnitude. The last two each have one bit pattern (the negation of zero) which doesn't represent a number.

二进制补码是或多或少通用的整数类型;但语言仍然允许其他人。

Two's complement is more or less universal for integer types these days; but the language still allows for the others.

这篇关于无符号窄字符类型数字表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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