representation is part of The Standard?

This question already has an answer here:

  • What do the C and C++ standards say about bit-level integer representation and manipulation? 8 answers
  • What does the C++ standard state the size of int, long type to be? 24 answers

  • The C standard discusses the representations of integer types in section 6.2.6.2.

    It specifies a binary representation for integer types. For unsigned types, the bits are divided into value bits and padding bits. Padding bits do not contribute to the value; there needn't be any padding bits. For signed types, there is a single sign bit. Signed types may be represented using either sign and magnitude, two's complement, or one's complement (two's complement is nearly universal for modern systems).

    The ordering of the bits, and the presence and number of padding bits, are implementation-defined. (Most modern implementations do not have padding bits).

    The concept of padding bits, and the restriction to the three canonical representations, were introduced in C99.

    The bitwise operators ( << , >> , & , et al) are defined in terms of the bits making up the representation of the values of the operands, but the requirements on the representations are specific enough that this is unambiguous for most cases. The description of the << and >> shift operators specifically says that, for example, the result of E1 << E2 is E1 × 2 E2 ; see section 6.5.7 of the cited N1570 draft.

    The C++ standard has a non-normative note that says it permits 2's complement, 1's complement and signed magnitude representations for integral types, but there doesn't seem to be an explicit statement that no other representations are permitted. It does require that "The representations of integral types shall define values by use of a pure binary numeration system.". You can see the gory details in the N4296 working draft of the C++ standard (or in any other draft, or in the standard itself if you have a copy).

    链接地址: http://www.djcxy.com/p/40406.html

    上一篇: 用哪种数据类型来以最佳方式存储数值

    下一篇: 代表是标准的一部分?