UNIHIVE

Study Hub UNIPORT CSC 284

CSC 284 · Introduction to Logic Design

Signed numbers and fixed-point representation

Sign-magnitude, one's complement and two's complement, ranges, and fixed-point fractions.

Our notes

1 min read

The 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

Watch

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.

All CSC 284 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.