WG14/N1570
6.2.6.2/2 For signed integer types, the bits of the object representation shall be divided into three
groups: value bits, padding bits, and the sign bit. There need not be any padding bits;
signed char shall not have any padding bits. There shall be exactly one sign bit.
Each bit that is a value bit shall have the same value as the same bit in the object
representation of the corresponding unsigned type (if there are M value bits in the signed
type and N in the unsigned type, then M ≤ N). If the sign bit is zero, it shall not affect
the resulting value. If the sign bit is one, the value shall be modified in one of the
following ways:
— the corresponding value with sign bit 0 is negated (sign and magnitude);
— the sign bit has the value −(2M) (two’s complement);
— the sign bit has the value −(2M − 1) (ones’ complement).
Which of these applies is implementation-defined, as is whether the value with sign bit 1
and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones’
complement), is a trap representation or a normal value. In the case of sign and
magnitude and ones’ complement, if this representation is a normal value it is called a
negative zero.
6.2.6.2/2 For signed integer types, the bits of the object representation shall be divided into three
groups: value bits, padding bits, and the sign bit. There need not be any padding bits;
signed char shall not have any padding bits. There shall be exactly one sign bit.
Each bit that is a value bit shall have the same value as the same bit in the object
representation of the corresponding unsigned type (if there are M value bits in the signed
type and N in the unsigned type, then M ≤ N). If the sign bit is zero, it shall not affect
the resulting value. If the sign bit is one, the value shall be modified in one of the
following ways:
— the corresponding value with sign bit 0 is negated (sign and magnitude);
— the sign bit has the value −(2M) (two’s complement);
— the sign bit has the value −(2M − 1) (ones’ complement).
Which of these applies is implementation-defined, as is whether the value with sign bit 1
and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones’
complement), is a trap representation or a normal value. In the case of sign and
magnitude and ones’ complement, if this representation is a normal value it is called a
negative zero.
解决方案
30
对于有符号整数,对象表示中的位可以分为三部分:数值位,填充位,符号位。
填充位可以不出现; signed char 不能含有填充位。符号位只能占用1位。
数值位中的每一位的所代表的数值,与改类型对应的无符号整数类型的对象表示中的对应位是一致的
(假如有符号类型有M个数值位,无符号类型有N个数值位,那么 M ≤ N)
假如符号位为0,符号位不影响结果值。
假如符号位为1,结果值必须经历以下几种修改之一:
— 对数值位所表示的值取反 (符号与绝对值表示;原码);
— 数值位表示的值 −(2^M) (补码);
— 数值位表示的值 −(2^M − 1) (反码).
具体使用哪一种方案由实现定义。对前两种表示,符号位为1,数值位全为0时,以及对最后一种表示,符号位与数值位全为1时,能否一个正常的数值也有实现定义。对于原码与反码,假如前述的表示是一个正常值,它将被称作负零。
填充位可以不出现; signed char 不能含有填充位。符号位只能占用1位。
数值位中的每一位的所代表的数值,与改类型对应的无符号整数类型的对象表示中的对应位是一致的
(假如有符号类型有M个数值位,无符号类型有N个数值位,那么 M ≤ N)
假如符号位为0,符号位不影响结果值。
假如符号位为1,结果值必须经历以下几种修改之一:
— 对数值位所表示的值取反 (符号与绝对值表示;原码);
— 数值位表示的值 −(2^M) (补码);
— 数值位表示的值 −(2^M − 1) (反码).
具体使用哪一种方案由实现定义。对前两种表示,符号位为1,数值位全为0时,以及对最后一种表示,符号位与数值位全为1时,能否一个正常的数值也有实现定义。对于原码与反码,假如前述的表示是一个正常值,它将被称作负零。
10
目的就是让三部分的总长度凑够8的倍数。原因是每字节8位。