Prof. Dr. Thorsten Jungmann (last updated 2026-11-02)
Relates to DET-01 Introduction to the module and its content
Task
Represent the following negative decimal numbers as signed binary numbers with the stated number of bits. The most significant bit is the sign bit.
One’s complement: a) −6 with 4 bits, b) −45 with 8 bits
Two’s complement: c) −3 with 4 bits, d) −100 with 8 bits
Solution
Given
Given explicitly:
- One’s complement: a) with bits, b) with bits
- Two’s complement: c) with bits, d) with bits
Known:
- Sign bit (DET-01): the most significant bit, 0 for positive and 1 for negative numbers
- One’s complement (DET-01): invert all bits of the positive counterpart
- Two’s complement (DET-01): invert all bits of the positive counterpart and add 1; formula:
- Range of two’s complement (DET-01):
Required
a) and b) the codes in one’s complement
c) and d) the codes in two’s complement
Pad the positive number with leading zeros to the full number of bits
Write the positive number with exactly bits, including its leading zeros, before you invert it. Only then does the sign bit end up in the most significant position.
One’s complement
The positive counterpart is written with bits; its most significant bit, the sign bit, must be 0. This is possible if the magnitude fits into the remaining bits, i.e. . Inverting all bits then gives the negative number, with the sign bit 1.
a) with 4 bits
Range: ✓
| Step | Bits |
|---|---|
| Positive number +6 | |
| Invert all bits: −6 |
in one’s complement with 4 bits:
Check: the positive and the negative code add up to 4 ones, ✓
b) with 8 bits
Range: ✓
| Step | Bits |
|---|---|
| Positive number +45 | |
| Invert all bits: −45 |
in one’s complement with 8 bits:
Check: the positive and the negative code add up to 8 ones, ✓
Two’s complement
Invert all bits of the positive counterpart and add 1. The formula serves as a check.
A shortcut and a second check
Scanning from right to left: Scan the bits of the positive number from right to left. Keep all bits up to and including the first 1, and invert all bits to its left. This gives the same code as inverting and adding 1: after inverting, this 1 has become a 0, and all bits to its right have become 1s. Adding 1 turns these 1s back into 0s and the 0 back into a 1, so the right-hand part of the positive number reappears unchanged.
Negative weight of the sign bit: In two’s complement, the sign bit has the negative weight ; all other bits keep their positive weights. Adding up the weights of the ones gives the value directly, including its sign:
where:
- is the value of the signed number
- is the bit at position , counted from the right and starting with 0
- is the number of bits
Read as an unsigned number, a negative code has the value . With the negative weight, the sign bit counts less, which leaves . A 1 in the sign bit therefore makes the number negative, and the other bits say how far it lies above .
c) with 4 bits
Range: ✓
| Step | Bits |
|---|---|
| Positive number +3 | |
| Invert all bits | |
| Add 1: −3 |
in two’s complement with 4 bits:
Alternatively, scanning from right to left: in , the first 1 from the right is the rightmost bit. It stays; the three bits to its left, , are inverted to . Together: ✓
Check with the formula: and ✓
Check with the negative weight of the sign bit: ✓
d) with 8 bits
Range: ✓
| Step | Bits |
|---|---|
| Positive number +100 | |
| Invert all bits | |
| Add 1: −100 |
When adding 1, the carry runs through the two 1s at the right end of the inverted bits: they become 0s, and the next 0 becomes a 1.
in two’s complement with 8 bits:
Alternatively, scanning from right to left: in , the first 1 from the right is the third bit. The three bits up to and including it stay; the five bits to their left, , are inverted to . Together: ✓
Check with the formula: and ✓
Check with the negative weight of the sign bit: ✓
