Binary, hexadecimal and number bases

IB CS Core — Topics 1–5 (SL & HL) · lesson 2 of 4 · 30 min

Binary, hexadecimal and number bases

topic: Topic 2

component:

Binary, hexadecimal, and number bases

Computers store all data in binary (base-2). Hexadecimal (base-16) is used as a compact human-readable representation of binary. The IB CS exam requires you to convert fluently between denary (base-10), binary, and hexadecimal.

Binary to denary conversion

Each binary digit has a place value that is a power of 2. Add the place values of all positions where the bit is 1. 128 + 32 + 16 + 4 + 1 = 181

Denary to binary conversion

Repeatedly divide by 2, recording remainders. Read remainders from bottom to top. Convert 75 to binary

75 ÷ 2 = 37 r 1 | 37 ÷ 2 = 18 r 1 | 18 ÷ 2 = 9 r 0

9 ÷ 2 = 4 r 1 | 4 ÷ 2 = 2 r 0 | 2 ÷ 2 = 1 r 0 | 1 ÷ 2 = 0 r 1

Result (bottom to top): 1001011

Verify: 64 + 8 + 2 + 1 = 75 ✓

Hexadecimal

Each hex digit represents exactly 4 binary bits (a nibble). To convert binary to hex, group bits into nibbles from the right and replace each with its hex equivalent. Convert 10111100 to hex

Group: 1011 | 1100

1011 = 11 = B 1100 = 12 = C

Result: BC

Verify: 11×16 + 12 = 176 + 12 = 188. Binary: 128+32+16+8+4 = 188 ✓

IB exam questions often ask you to show working. Always write out the nibble grouping and the conversion table — even if you can do it in your head.

Two’s complement

Two’s complement is the standard way to represent negative integers in binary. The most significant bit (MSB) is the sign bit: 0 = positive, 1 = negative. To negate a number: invert all bits, then add 1. Represent −45 in 8-bit two’s complement

45 in binary: 00101101

Invert all bits: 11010010

Add 1: 11010011

Verify: −128 + 64 + 16 + 2 + 1 = −128 + 83 = −45 ✓

Knowledge check

  • Question of
  • Hide hint
  • Show hint

✓ Correct! ✕ Not quite

  • Try again
  • See results
  • Next question
  • Check answer

Previous lesson: CPU architecture: ALU, CU, registers, buses
Back to IB CS Core — Topics 1–5 (SL & HL)
Next lesson: Linear and binary search