Two's complement
Two’s complement is a fixed-width positional binary representation of signed integers in which the highest-order bit has negative weight and the remaining bits have positive weights.
Modern C
Two's complement representation encodes negative integers by complementing the corresponding positive representation and adding one, with the high-order bit indicating negativity.
- How it is used
- Explains how C interprets signed bit patterns and constructs negative values from unsigned-style arithmetic.
- How deep it goes
- Works through bit-level negation and contrasts three sign representations, but stops short of a full signed-arithmetic treatment.
- Examples
- Uses a 16-bit negation table, the identity ~A + 1, and fixed-width int64_t expressions.
- What you can do after
- Evaluate signed bit patterns and compute negative values using complement-and-add-one reasoning.
Modern C, Third Edition
Two's complement is a signed-integer representation in which the high-order bit contributes negative weight and the remaining bits contribute positive weights.
- How it is used
- Explains how C interprets signed integer bit patterns and relates them to unsigned arithmetic.
- How deep it goes
- Defines sign-bit interpretation, constructs negatives with ~A + 1, and demonstrates signed ordering across unsigned representations.
- Examples
- Uses 16-bit negation of 240 and functions that classify and compare unsigned values as signed.
- What you can do after
- Evaluate signedness and signed ordering from unsigned bit patterns, and construct negatives with bitwise operations.
Read how Modern C, Third Edition explains two's complement →
Clojure: The Essential Reference
Two's complement is a binary representation of signed integers in which negative values are encoded by complementing the bits of their magnitudes and adding one.
- How it is used
- Explains signed integer overflow and bit-shift behavior in Clojure's numeric and bitwise operations.
- How deep it goes
- Works through 32-bit and 64-bit boundary layouts, then applies the representation to arithmetic and logical shifts.
- Examples
- Uses 32-bit and 64-bit boundary tables plus binary-string demonstrations of negative right shifts.
- What you can do after
- Evaluate signed overflow and interpret arithmetic versus unsigned right shifts in Clojure.
Read how Clojure: The Essential Reference explains two's complement →
Building Quantum Software with Python
Two's complement is a signed binary representation in which the leading bit distinguishes nonnegative values from negative values and an m-bit string represents values from −2^(m−1) through 2^(m−1)−1.
- How it is used
- Represents negative outputs in fixed-width quantum value registers and supports searches for nonnegative function outcomes.
- How deep it goes
- Defines sign-bit ranges and demonstrates four-bit encodings, but does not derive two's complement arithmetic.
- Examples
- Uses f(k)=k²−3 with output 1101 for −3 and f(k)=k²−5 with a four-qubit range from −8 through 7.
- What you can do after
- Apply it via build_polynomial_circuit, grid_state, and oracle_match_0 to encode and search signed quantum function outputs.
Read how Building Quantum Software with Python explains two's complement →
Related concepts
- sign representationkind of · A sign representation is a scheme for encoding the sign and magnitude of a signed numerical value in bits.
- binary stringuses · A binary string is a finite, ordered sequence of binary digits, each having the value zero or one.
- integerimplements · An integer is a whole-number value with no fractional part, including negative numbers, zero, and positive numbers.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



