sign extension

J.S.Schwarz jss at sfjec.UUCP
Sat Jul 28 03:31:28 AEST 1984


The paragraphs in section 3.2 of the latest version of the  ANSI
Draft (dated July 11) dealing with conversions between  signed and
unsigned follows:

    "When a signed integer is combined with or assigned to an
    unsigned integer of equal or greater length, the signed integer
    is converted to unsigned and the result is unsigned. If the value
    of the signed integer is negative, the conversion  involves
    adding to it the largest number that can be represented in the
    unsigned integer plus one.  In a twos-complement representation,
    there is no actual change in the bit pattern except filling the
    high-order bits with copies of the sign bit if the unsigned
    integer is wider.

    When an unsigned integer is converted to a longer signed integer
    (for example, by assignment) its value is unchanged."

These paragraphs also govern conversion by casting.
Except that they don't cover conversions of unsigned to
equal or shorter types, they seem to be unambiguous.
This ambiguity is partialy covered by a sentence of paragraph 3.1
that says "When a longer integer is converted to a shorter integer
or to a char, it is truncated by discarding high-order bits."

Jerry Schwarz



More information about the Comp.lang.c mailing list