Skip to main content
SingaporeComputer ScienceSyllabus dot point

How do computers represent numbers in binary and hexadecimal, and how do we convert between bases reliably?

Convert whole numbers between binary, denary and hexadecimal, and perform binary addition, explaining the role of place value and overflow

A focused answer to the H2 Computing outcome on number bases. Place value in binary and hexadecimal, conversion methods between binary, denary and hexadecimal, binary addition, and the meaning of overflow.

Generated by Claude Opus 4.88 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

SEAB wants you to convert whole numbers fluently between binary (base 2), denary (base 10) and hexadecimal (base 16), to add binary numbers showing carries, and to explain place value and overflow. The central idea is that every base uses the same positional rule - each column is the base raised to a power - so conversion is just a change of which powers you count in.

The answer

Place value in any base

In any base bb, the digit in the column ii places from the right is worth that digit times bib^i. In binary the columns are powers of two:

, 23=8, 22=4, 21=2, 20=1\dots,\ 2^3 = 8,\ 2^2 = 4,\ 2^1 = 2,\ 2^0 = 1

So 10112=8+0+2+1=111011_2 = 8 + 0 + 2 + 1 = 11. In hexadecimal the columns are powers of sixteen, and the digits run 00 to 99 then A\text{A} to F\text{F} for the values ten to fifteen.

Denary to binary

Two reliable methods:

  1. Subtract descending powers of two. Write the place values 128,64,32,,1128, 64, 32, \dots, 1. For the number, put a 11 under the largest power that fits, subtract it, and repeat with the remainder.
  2. Repeated division by 2. Divide the number by 2, recording remainders. The remainders read bottom-to-top give the binary digits.

Binary to hexadecimal and back

Because 16=2416 = 2^4, one hex digit equals exactly four binary bits (a nibble). To go binary to hex, group the bits into nibbles from the right (pad the left with zeros) and convert each nibble. To go hex to binary, expand each hex digit to its four-bit pattern.

binary:  1101 0110
hex:        D    6     -> 0xD6

Binary addition

Add column by column from the right, exactly like denary but carrying whenever a column reaches 2:

0 + 0 = 0
0 + 1 = 1
1 + 1 = 10  (write 0, carry 1)
1 + 1 + 1 = 11  (write 1, carry 1)

Overflow

A fixed-width register can only hold so many bits. If an addition produces a carry out of the most significant bit that there is no column to hold, the result is wrong - this is overflow. For an unsigned nn-bit number the range is 00 to 2n12^n - 1; a result beyond it overflows.

Examples in context

Example 1. Colour codes on the web. A web colour like #1E90FF is three pairs of hex digits giving the red, green and blue intensities. Each pair is one byte (eight bits), so 1E is 3030, 90 is 144144 and FF is 255255. Reading colours in hex is exactly the nibble-grouping trick applied to bytes.

Example 2. Memory addresses. Debuggers print addresses such as 0x7FFE because hex packs a 16-bit address into four readable digits. An engineer reading 0xFF instantly knows all eight bits of that byte are set, which would be tedious to see in raw binary.

Try this

Q1. Convert 0xB30xB3 to denary. [2 marks]

  • Cue. B=11\text{B} = 11 so the high nibble is 11×16=17611 \times 16 = 176, and 33 adds 33, giving 179179.

Q2. Convert 156156 to 8-bit binary. [2 marks]

  • Cue. 156=128+16+8+4=100111002156 = 128 + 16 + 8 + 4 = 10011100_2.

Q3. Add 00111111200111111_2 and 00000001200000001_2 and state the result in binary. [2 marks]

  • Cue. 63+1=64=01000000263 + 1 = 64 = 01000000_2; the run of ones rolls over with carries to set the next bit.

Exam-style practice questions

Practice questions written in the style of SEAB exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

Original5 marks(a) Convert the denary number 217217 to 8-bit binary. (b) Convert your binary answer to hexadecimal. (c) State why hexadecimal is convenient for writing binary values.
Show worked answer →

(a) Use repeated division by 2, or subtract descending powers of two. The place values are 128,64,32,16,8,4,2,1128, 64, 32, 16, 8, 4, 2, 1. We have 217=128+64+16+8+1217 = 128 + 64 + 16 + 8 + 1, so the bits set are at 128,64,16,8,1128, 64, 16, 8, 1:

128  64  32  16   8   4   2   1
  1   1   0   1   1   0   0   1

So 217=110110012217 = 11011001_2.

(b) Group the 8 bits into two nibbles of 4 bits: 11011101 and 10011001. 11012=13=D1101_2 = 13 = \text{D} and 10012=91001_2 = 9. So 217=D916217 = \text{D9}_{16}.

(c) Each hexadecimal digit maps to exactly four binary bits, so a long binary string compresses to a quarter of the digits and is far easier to read and transcribe without error.

Markers reward the correct place-value working, the nibble grouping for hex, and a clear reason (one hex digit equals four bits).

Original4 marksAdd the 8-bit binary numbers 0110111001101110 and 0101101001011010. Show your carries, give the 8-bit result, and state whether overflow has occurred if these are treated as unsigned 8-bit integers.
Show worked answer →

Add bit by bit from the right, carrying where a column sums to 2 or 3:

  carries: 1 1 1 1 1 0 0
           0 1 1 0 1 1 1 0
         + 0 1 0 1 1 0 1 0
         -----------------
           1 1 0 0 1 0 0 0

The result is 11001000211001000_2. In denary, 011011102=11001101110_2 = 110 and 010110102=9001011010_2 = 90, and 110+90=200=110010002110 + 90 = 200 = 11001000_2, which checks.

An unsigned 8-bit number can hold 00 to 255255. Since 200255200 \le 255 and there is no carry out of the most significant bit (the leftmost column), there is no overflow.

Markers reward correct carry propagation, the 8-bit result, and the overflow test (a carry out of the top bit, or a result exceeding the range).

Related dot points