bit_logic > Concepts > Signed Integrals

Signed Integrals

Signed integral representation is not defined by the C++ Standard ( Sect 3.9.1 "Fundamental Type"), other than to say :

The representations of integral types shall define values by use of a pure binary numeration system 44) [Example:this International Standard permits 2's complement, 1's complement and signed magnitude representations for integral types. ]

44) 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 theAmerican National Dictionary for Information Processing Systems.)

This definition allows for 3 different binary representations of negative numbers. Positive numbers have a guaranteed binary representation, but their negative counterparts are implementation dependent. To handle how we encode these bits in a Bit Container, we have 3 template selector classes, which can be used as template arguments to the packing / unpacking functions. These are :

  • ones_complement
  • twos_complement
  • signed_magnitude

Without using the selector class version the default binary encoding for a negative signed value is "2's complement".

The native integral representation is defaulted to be "2's complement", but to override you need to use a define before including andy Bit Logic libraries. If there is a more "boost" like way to do this please tell me . Defines are :

  • BOOST_ONES_COMPLEMENT_INTEGRALS
  • BOOST_SIGNED_MAGNITUDE_INTEGRALS