University of Auckland · FACULTY OF COMPUTER SCIENCE

COMPSCI110 · Introduction to Computer Systems

- one subject, every graph, every model, every mark
Computer Science14 Chapters8-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 1 of 11 · COMPSCI 110

Data as Binary

Module 1 of University of Auckland COMPSCI110 is the foundation: how every kind of data — whole numbers, negative numbers, fractions, text, sound and images — is encoded as binary. You convert between decimal, binary, octal and hexadecimal, add and subtract in binary, represent signed integers three different ways (sign-magnitude, one's complement and two's complement), handle binary fractions and the textbook floating-point format, and encode text with ASCII/UTF-8 and compress it with Huffman and run-length encoding. It carries 4 marks on the final exam and is heavily tested in the mid-semester test — and two's complement is the module's single biggest mark-loser.

In this chapter

What this chapter covers

  • 01Positional bases: binary (2), octal (8), hexadecimal (16) and decimal; convert by powers, by repeated ÷2 (read remainders bottom-up), and by grouping bits in 3s → octal / 4s → hex
  • 02Binary addition (1+1 = 10, carry 1) and subtraction (borrow adds the base); arithmetic overflow when a value exceeds the fixed bit-width
  • 03Three signed representations: sign-magnitude, one's complement and two's complement — the MSB is the sign bit in all three
  • 04Ranges: two's complement is asymmetric −2ⁿ⁻¹ … 2ⁿ⁻¹−1 with ONE zero; sign-magnitude and one's complement are ±(2ⁿ⁻¹−1) with TWO zeros
  • 05Binary fractions (2⁻¹, 2⁻², …), left/right shift as ×2 / ÷2, and the textbook 16-bit floating-point format (sign · mantissa · exp-sign · exponent)
  • 06Text encoding: 7-bit ASCII (128 values) and variable-width UTF-8 (1–4 bytes, keeps ASCII); upper/lower case differ by one bit
  • 07Compression: Huffman (lossless, frequent symbols get shorter prefix-free codes) and run-length encoding; compression ratio = uncompressed ÷ compressed
Worked example · free

−9 in 5-bit two's complement (and why it checks out)

Q [4 marks]. Using 5-bit two's complement, write the representation of −9. Then verify it by adding it to +9, and state the full 5-bit signed range.
  • +1Start from the positive value in 5 bits: +9 = 01001₂ (8 + 1). The leading 0 is the sign bit (positive).
  • +1Take the one's complement — invert every bit: 01001 → 10110₂.
  • +1Add 1 to get the two's complement: 10110 + 1 = 10111₂. So −9 = 10111₂ (the leading 1 marks it negative).
  • +1Check by adding +9 and −9: 01001 + 10111 = 1 00000₂; discard the carry out of the sign bit → 00000₂ = 0. ✓ And the 5-bit two's-complement range is −2⁴ … 2⁴−1 = −16 … +15, so −9 is representable.
−9 = 10111₂ (5-bit two's complement). Adding +9 (01001) gives 1 00000, and dropping the carry leaves 0 — confirming the encoding. The 5-bit signed range is −16 … +15.
Sia tip — Two traps cost the most marks: forgetting the +1 (that leaves one's complement, 10110, which is off by one), and quoting a symmetric range. Only two's complement is asymmetric — it reaches −16 but not +16 in 5 bits, because the most-negative value has no positive twin. Ask Sia to drill signed conversions until invert-then-add-1 is automatic.
Glossary

Key terms

Radix (base)
The number of distinct digits a positional system uses: base-2 (binary, digits 0–1), base-8 (octal, 0–7), base-16 (hexadecimal, 0–9 then A–F = 10–15) and base-10 (decimal). Each position is a power of the base, so a base-b number is the sum of digit × bᵖᵒˢⁱᵗⁱᵒⁿ.
Sign bit (MSB)
The most-significant (leftmost) bit, which in all three signed representations indicates sign: 0 = positive, 1 = negative. Because the bit-width is fixed, a signed conversion has no unique answer unless the number of bits is stated.
One's complement
A signed representation where a negative number is the bit-by-bit inversion of the positive (+5 = 00101 → −5 = 11010). It has two zeros (+0 and −0) and the symmetric range ±(2ⁿ⁻¹−1); it is a stepping stone to two's complement.
Arithmetic overflow
When the true result of an operation is too large (or too small) to fit the fixed bit-width — e.g. adding 14 + 2 in 4 bits. The hardware silently keeps only the low bits, so detecting overflow is a real concern in fixed-width arithmetic.
Textbook floating-point format
The course's 16-bit layout: 1 bit for the sign of the mantissa, 9 mantissa bits, 1 bit for the sign of the exponent and 5 exponent bits. The value is normalised so the binary point sits just left of the first 1 (the mantissa is a fraction 0.1…), e.g. −120 encodes to F807₁₆.
Huffman coding
A lossless compression scheme that gives more-frequent symbols shorter codes and builds a prefix-free code (no code is the start of another), so a stream decodes unambiguously left-to-right. Compression ratio = uncompressed size ÷ compressed size.
FAQ

Data as Binary FAQ

What's the difference between one's and two's complement?

Both put the sign in the leading bit and both negate by inverting bits, but two's complement adds 1 after inverting. That single +1 removes the duplicate zero (two's complement has one zero, the others have +0 and −0) and makes the range asymmetric: n-bit two's complement runs −2ⁿ⁻¹ … 2ⁿ⁻¹−1, while one's complement and sign-magnitude run ±(2ⁿ⁻¹−1). Two's complement wins in practice because subtraction can reuse the adder — you never need separate subtractor hardware.

How do I convert a decimal number to binary quickly?

Repeatedly divide by 2, writing down the remainder each time, then read the remainders bottom-up. For example 766 → … → 1011111110₂. A fast sanity check: an odd number always ends in 1 and an even number ends in 0. For fractions, do the opposite — repeatedly multiply the fraction by 2 and read the integer parts top-down (0.1875 → 0.0011₂).

Can AI help me with binary and two's complement in COMPSCI110?

Yes, as a study aid. Sia can walk a base conversion digit by digit, show the invert-then-add-1 steps for a two's-complement negative, check whether your result falls in the valid range, and generate fresh practice at any bit-width. Use it to understand and rehearse the method — it explains and drills but does not sit the mid-semester test or exam for you, and the University of Auckland's academic-integrity rules apply to those controlled assessments.

Is Module 1 on the final exam?

Yes. Data-as-binary (base conversion, binary arithmetic and signed numbers) carries 4 marks on the final exam and is also tested in the mid-semester test — so it is examined twice. Because the questions are mechanical, they are reliable marks if you have drilled conversions and two's complement, and a reliable place to drop marks if you haven't. Confirm the current exam coverage on Canvas.

Why must I be told the number of bits for a signed conversion?

Because the sign bit is a position, not a symbol. −5 is 11011 in 5-bit two's complement but 11111011 in 8-bit — the leading 1s that mark it negative depend entirely on the width. Unsigned conversions have a unique answer; signed ones don't until the bit-width is fixed, so a question that asks for a signed value without a width is under-specified.

Study strategy

Exam move

Make the mechanical procedures automatic on paper before the test — this module rewards speed and precision, not insight. Drill three routines until they're reflexive: decimal→binary by repeated ÷2 (remainders bottom-up), the grouping shortcut (3 bits → octal, 4 bits → hex from the right), and two's complement by invert-then-add-1. Memorise the range rule and say it out loud: only two's complement is asymmetric, −2ⁿ⁻¹ … 2ⁿ⁻¹−1; the other two are ±(2ⁿ⁻¹−1) with two zeros. Keep the floating-point field layout (1 · 9 · 1 · 5) on your one-page sheet and practise one encode and one decode. For text and compression, learn the facts that get asked as MCQ distractors: UTF-8 is 1–4 bytes and preserves ASCII, Huffman is lossless with shorter codes for frequent symbols and prefix-free decoding, and compression ratio = uncompressed ÷ compressed. Since Module 1 is examined in both the test and the final, a few timed conversion sets pay off twice.

Working through Data as Binary in COMPSCI 110? Sia is AskSia’s AI Computer Science tutor — ask any COMPSCI 110 Data as Binary question and get a clear, step-by-step explanation grounded in how COMPSCI 110 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 12 of your University of Auckland subjects - and 1,000+ Bibles across every Australian university.
Sia - your COMPSCI110 tutor, unlimited, worked the way the exam marks it
The full 8-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$25/ month
30-day money-back · cancel in one tap · how it works
Unlock the full COMPSCI110 Bible + 12 University of Auckland subjects解锁完整 COMPSCI110 Bible + University of Auckland 12 门科目
$25/mo