liveBook · Manning

Sign bit

As explained in Modern C

A sign bit is the bit in a signed representation that indicates whether the represented value is non-negative or negative.

A sign bit is the additional bit in a C signed integer representation that indicates the sign: 0 represents a positive value, while 1 represents a negative value. Positive values retain the representation they have in the corresponding unsigned type; the sign bit affects how the upper part of the representation is interpreted. section 5.7.5

C permits three ways to use the sign bit:

  • Sign and magnitude keeps the magnitude positive and uses the sign bit as a minus sign. section 5.7.5
  • Ones’ complement complements every bit of the corresponding positive value. section 5.7.5
  • Two’s complement, commonly used on modern platforms, interprets unsigned values whose high-order bit is 1 as negative. section 5.7.5

Negating an unsigned bit pattern

For a 16-bit value A = 240, the two’s-complement negative is formed as ~A + 1: complementing 0000000011110000 produces 1111111100001111, then adding one produces 1111111100010000, or 65296 as unsigned. section 5.7.5

How Modern C covers it

How deep it goes
Defines the bit and compares three representations, then works through two’s-complement negation without developing full integer semantics.
Examples
Uses a 16-bit negation table and C functions that classify unsigned values and compare them as signed values.
What it assumes
Assumes familiarity with binary representations, unsigned integers, bit complementation, and addition.
What you can do after
Evaluate signed interpretations of unsigned bit patterns and construct two’s-complement negatives using bitwise operations.
How it connects
Connects signed integers with unsigned integers, integer rank, sign and magnitude, ones’ complement, and two’s complement.

Also explained in

Compare how 2 books explain sign bit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.