CSC 284 · Introduction to Logic Design
Our notes
1 min readThe problem
A computer has no minus sign; it must code negative numbers in bits. Three ways are taught, all using the leftmost bit as the sign (0 positive, 1 negative).
Sign-magnitude
Sign bit plus the size. In 8 bits, +25 = 0001 1001 and −25 = 1001 1001. Simple to read, but there are two zeros (0000 0000 and 1000 0000) and adding needs extra logic.
One's complement
Negative numbers are formed by flipping every bit. −25 = 1110 0110. Still two zeros; an end-around carry is needed in addition.
Two's complement
Flip every bit and add 1. −25 = 1110 0110 + 1 = 1110 0111.
- One zero only.
- Ordinary binary addition works for positive and negative numbers.
- The top bit has weight −2ⁿ⁻¹: 1110 0111 = −128 + 64 + 32 + 4 + 2 + 1 = −25.
Ranges with n bits
- Unsigned: 0 to 2ⁿ − 1 (8 bits: 0 to 255).
- Sign-magnitude and one's complement: −(2ⁿ⁻¹ − 1) to +(2ⁿ⁻¹ − 1) (8 bits: −127 to +127).
- Two's complement: −2ⁿ⁻¹ to +(2ⁿ⁻¹ − 1) (8 bits: −128 to +127).
Worked example: subtraction by addition
Find 37 − 58 in 8-bit two's complement.
- 37 = 0010 0101; 58 = 0011 1010 so −58 = 1100 0101 + 1 = 1100 0110.
- 0010 0101 + 1100 0110 = 1110 1011.
- Top bit 1, so negative: flip and add 1 → 0001 0101 = 21. Answer −21. Correct.
Signed overflow
Adding two positives that give a negative (or two negatives that give a positive) means overflow. 0111 0000 (112) + 0010 0000 (32) = 1001 0000, which reads as −112: 144 does not fit in 8-bit two's complement.
Sign extension
To widen a two's complement number, copy the sign bit: −3 in 4 bits is 1101; in 8 bits it is 1111 1101.
Fixed-point numbers
The binary point is placed at an agreed position. In an 8-bit format with 4 integer and 4 fraction bits, 0110 1100 means 0110.1100 = 6.75. Fixed point is fast and used in small controllers and DSP chips, but its range is small.
Exams usually ask
- Write a negative number in all three forms and give ranges.
- Subtract by adding the two's complement and detect overflow.
Common mistake
Forgetting to add 1 after flipping the bits: that gives one's complement, not two's complement.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Negative Binary Numbers | Binary Arithmetic | Electronics Textbook
(opens allaboutcircuits.com in a new tab)
-
Two's complement
(opens en.wikipedia.org in a new tab)
Wikipedia, Two's complement, CC BY-SA 4.0 · licence
-
Signed number representations
(opens en.wikipedia.org in a new tab)
Wikipedia, Signed number representations, CC BY-SA 4.0 · licence
-
Fixed-point arithmetic
(opens en.wikipedia.org in a new tab)
Wikipedia, Fixed-point arithmetic, CC BY-SA 4.0 · licence
-
NPTEL: Switching Circuits and Logic Design (IIT Kharagpur, Prof. Indranil Sengupta)
Video lectures, many hours in all: watch on Wi-Fi where you can.
(opens nptel.ac.in in a new tab)
NPTEL, NPTEL: Switching Circuits and Logic Design (IIT Kharagpur, Prof. Indranil Sengupta), CC BY-NC-SA 4.0 · licence
-
NPTEL: Digital Circuits and Systems (IIT Madras, Prof. Shankar Balachandran)
Video lectures, many hours in all: watch on Wi-Fi where you can.
(opens nptel.ac.in in a new tab)
NPTEL, NPTEL: Digital Circuits and Systems (IIT Madras, Prof. Shankar Balachandran), CC BY-NC-SA 4.0 · licence
Watch
-
Best pick Data Representation using 2's Complement
8 min · ≈ 36 MB · about ₦20
(opens youtube.com in a new tab)
-
1.2.12 Worked Examples: Two's Complement Representation
6 min · ≈ 27 MB · about ₦15
(opens youtube.com in a new tab)
-
Binary: Plusses & Minuses (Why We Use Two's Complement) - Computerphile
16 min · ≈ 72 MB · about ₦40
(opens youtube.com in a new tab)
-
Twos complement: Negative numbers in binary
14 min · ≈ 63 MB · about ₦35
(opens youtube.com in a new tab)
-
3 - Digital Logic - Signed Numbers (signed magnitude, one's complement, two's complement)
45 min · ≈ 203 MB · about ₦114
(opens youtube.com in a new tab)
Practise
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.