📘 CodingMarble Learn

Number Systems and Encoding

A number system is a way to write numbers using a set of digits and a base. Decimal (base 10) uses 0–9, binary (base 2) uses 0 and 1, octal (base 8) uses 0–7, and hexadecimal (base 16) uses 0–9 and A–F. To go from decimal to any base, divide repeatedly by the base and read remainders bottom to top; for fractions, multiply by the base and read the integer parts top to bottom. To go to decimal, multiply each digit by its place value and add. Binary ↔ octal uses groups of 3 bits, binary ↔ hex groups of 4. Text is stored with encoding schemes: ASCII (7-bit, 128 characters), ISCII (8-bit, Indian scripts) and Unicode (every script), stored as UTF-8 (1–4 bytes) or UTF-32 (4 bytes).

🎬 Step-by-step story

  1. In decimal each place is 10 times bigger. 345 means 3 hundreds, 4 tens and 5 ones.
  2. Binary uses only 0 and 1. Each place is 2 times bigger. Divide 13 by 2 again and again, and read the remainders from the bottom: 1101.
  3. To turn binary into decimal, add the place values of the 1s. 1011 is 8 + 2 + 1 = 11.
  4. Octal groups bits in threes. Hexadecimal groups them in fours. 11010110 is D6 in hex and 326 in octal.
  5. Letters are stored as numbers. In ASCII, A is 65. Unicode has a code for every script. UTF-8 uses 1 to 4 bytes; UTF-32 always 4.
  6. Your turn: slide the number and see its binary, octal, hex and letter.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why do computers use binary and not decimal?

A circuit can be reliably on or off. Two states match two digits, 1 and 0, so binary is simplest and least error-prone.

Why read remainders from the bottom?

The first remainder is the ones place (smallest). The last one is the biggest place, so it must be written first. Watch the blocks fill from the right.

Why are octal and hex useful if computers use binary?

Long binary strings are hard for people to read. Hex writes 4 bits as one symbol, so 11010110 becomes just D6.

Why does Hindi take more bytes than English in UTF-8?

UTF-8 keeps the first 128 codes (English) in 1 byte. Characters with bigger code points, like Devanagari, need 3 bytes.

Number systems: base and place value

Every number system has a base (radix) = how many digits it uses. Each place is worth baseposition.

SystemBaseDigits
Binary20, 1
Octal80–7
Decimal100–9
Hexadecimal160–9, A(10)–F(15)

We write the base as a subscript: (1011)2, (17)8, (2F)16.

Decimal to binary, octal and hexadecimal

Whole part: divide by the new base again and again, write each remainder, stop at 0, and read remainders from bottom to top.

Example: 25 → binary: 25÷2 = 12 r1, 12÷2 = 6 r0, 6÷2 = 3 r0, 3÷2 = 1 r1, 1÷2 = 0 r1 → (11001)2.

Fraction part: multiply by the base, take the whole-number part as the next digit, repeat with the fraction, read top to bottom. Example: 0.625 × 2 = 1.25 (1), 0.25 × 2 = 0.5 (0), 0.5 × 2 = 1.0 (1) → (0.101)2.

Binary, octal and hexadecimal to decimal

Multiply each digit by its place value and add.

(1101)2 = 1×8 + 1×4 + 0×2 + 1×1 = 13.

(157)8 = 1×64 + 5×8 + 7×1 = 111.

(2F)16 = 2×16 + 15×1 = 47.

After the point the places are base−1, base−2…: (10.11)2 = 2 + 0.5 + 0.25 = 2.75.

Binary ↔ octal ↔ hexadecimal

8 = 2³, so one octal digit = 3 bits. 16 = 2⁴, so one hex digit = 4 bits.

Binary → octal/hex: group bits from the right (add 0s on the left if needed) and write each group's value. (11010110)2 → 011 010 110 → (326)8; 1101 0110 → (D6)16.

Octal/hex → binary: write each digit as 3 or 4 bits. (5A)16 = 0101 1010.

Octal ↔ hex: go through binary.

Encoding schemes: ASCII, ISCII and Unicode

A computer stores every character as a number called its code. An encoding scheme is the agreed table of codes.

Unicode code points are stored using UTF formats:

Board exam focus

Expect 1–3 mark conversions (show every division or multiplication step), 'why is Unicode needed', and UTF-8 vs UTF-32.

Key formulas and definitions

Worked examples

1. Convert (45)₁₀ to binary.

45÷2=22 r1; 22÷2=11 r0; 11÷2=5 r1; 5÷2=2 r1; 2÷2=1 r0; 1÷2=0 r1. Read up: (101101)₂.

2. Convert (110110)₂ to decimal.

32 + 16 + 0 + 4 + 2 + 0 = 54.

3. Convert (156)₁₀ to hexadecimal.

156÷16 = 9 r12 (C); 9÷16 = 0 r9. Read up: (9C)₁₆.

4. Convert (725)₈ to binary and then to hexadecimal.

7 = 111, 2 = 010, 5 = 101 → 111010101. Groups of 4 from the right: 0001 1101 0101 → (1D5)₁₆.

5. Convert (0.375)₁₀ to binary.

0.375×2 = 0.75 (0); 0.75×2 = 1.5 (1); 0.5×2 = 1.0 (1). Read down: (0.011)₂.

6. Convert (1A.8)₁₆ to decimal.

1×16 + 10×1 + 8×16⁻¹ = 16 + 10 + 0.5 = 26.5.

7. How many bytes does 'नमस्ते' (6 Unicode characters) take in UTF-8 and in UTF-32?

Each Devanagari character is 3 bytes in UTF-8: 6 × 3 = 18 bytes. In UTF-32 each is 4 bytes: 6 × 4 = 24 bytes.

Common mistakes

Practice quiz

1. (1010)₂ in decimal is:
2. The base of the hexadecimal system is:
3. How many bits make one octal digit?
4. ASCII code of 'A' is:
5. Which encoding uses a fixed 4 bytes per character?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

How do you convert decimal to binary?

Divide the number by 2 repeatedly, write the remainders, and read them from bottom to top.

What is the difference between ASCII and Unicode?

ASCII is a 7-bit code with 128 English characters. Unicode gives a unique code to every character of all languages and is stored as UTF-8, UTF-16 or UTF-32.

What is the difference between UTF-8 and UTF-32?

UTF-8 uses 1 to 4 bytes per character (saves space); UTF-32 always uses 4 bytes (simple but larger).

Where this is taught

PolandSzkoła podstawowa, klasa VIIUnderstanding, analysing and solving problems
PolandSzkoła podstawowa, klasa VIIIUnderstanding, analysing and solving problems
Spain2º ESONumber sense
Ukraine10 класElective: mathematical foundations of informatics (35 h)
Ukraine11 класElective: mathematical foundations of informatics (35 h)
CBSE (India)Class 11Numbers, Quantification and Numerical Applications
CBSE (India)Class 11Computer Systems and Organisation
England (GCSE, A level)Year 9Computer science
England (GCSE, A level)Year 103.3 Fundamentals of data representation
England (GCSE, A level)Year 124.5 Fundamentals of data representation
England (GCSE, A level)Year 134.5 Data representation (A-level)
Japan高校1年Communication and information design
South Korea중학교 2학년Data
South Korea중학교 3학년Data and information
South Korea고등학교 3학년Data and information
FrancePremièreData representation
Russia7 классTheoretical foundations
Russia8 классTheoretical foundations
Russia8 классTheoretical foundations
Russia10 классTheoretical foundations
Russia10 классTheoretical foundations
China高一Comp.1 Ch.1 Data and big data

Learn first

Related lessons

All Computer Science lessons