Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🖥️ Unit 1 – Computer Systems & Organisation  ·  Lesson 04

Number Systems: Binary, Octal, Hex

Why do computers use binary?

Inside a computer, every circuit is like a tiny switch that is either ON or OFF — current flows or it does not. Two states are easy to make and very reliable, so computers represent everything with two digits: 1 (ON) and 0 (OFF). This is the binary number system. Numbers, letters, photos, music and even Python programs are finally stored as patterns of 0s and 1s.

switches →ONOFFONON
Four switches → 1 0 1 1 → the number 11 in decimal

Base (radix) and place value

The base (or radix) of a number system is the number of different digits it uses. In every positional system, the value of a digit depends on its position. Positions are numbered 0, 1, 2 … from the right, and each position has a weight of baseposition.

SystemBaseDigits usedExample
Decimal100 1 2 3 4 5 6 7 8 9(725)₁₀
Binary20 1(1011)₂
Octal80 1 2 3 4 5 6 7(375)₈
Hexadecimal160–9 and A B C D E F (A=10 … F=15)(2AF)₁₆

Decimal (base 10)

This is the system we use every day. In 725: 7 is in the hundreds place, 2 in the tens place and 5 in the ones place.

DigitPositionWeightValue
7210² = 100700
2110¹ = 1020
5010⁰ = 15
725 = 700 + 20 + 5

Binary (base 2)

Only digits 0 and 1 are allowed. Each binary digit is a bit. Place values double from right to left: 1, 2, 4, 8, 16, 32, 64, 128 …

weight →1286432168421
Place values of an 8-bit binary number
bits →00101101
(00101101)₂ = 32 + 8 + 4 + 1 = 45

The right-most bit is the Least Significant Bit (LSB); the left-most is the Most Significant Bit (MSB). A binary number ending in 0 is even; ending in 1 is odd.

Octal (base 8)

Octal uses digits 0 to 7. Weights are 1, 8, 64, 512 … Since 8 = 2³, one octal digit = exactly 3 bits. Octal was popular in early computers and is still used for file permissions in Linux, e.g. chmod 755.

Example: (57)₈ = 5 × 8 + 7 × 1 = 40 + 7 = 47 in decimal.

Hexadecimal (base 16)

Hexadecimal needs 16 symbols, so after 9 we use letters: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Since 16 = 2⁴, one hex digit = exactly 4 bits. Weights are 1, 16, 256, 4096 …

🎨
Colour codes#FF0000 is red: FF red, 00 green, 00 blue.
🧠
Memory addressesDebuggers show addresses like 0x7ffe4a10.
📶
MAC addressNetwork cards: 3C:52:82:1A:9F:07.
🔤
UnicodeHindi letter अ is U+0905.
Where you will see hexadecimal

Example: (2F)₁₆ = 2 × 16 + 15 × 1 = 32 + 15 = 47.

Comparison table 0–16

Instead of copying a table, let Python print it for you. Look how hex reaches F at 15, and octal "carries" to 10 at 8.

Python
print('Dec  Bin   Oct  Hex')
for n in range(0, 17):
    print(f'{n:>3}  {n:>04b}  {n:>3o}  {n:>3X}')
Dec Bin Oct Hex 0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F 16 10000 20 10
💡 Memory trick

Learn binary of 0–15 by heart (the 4-bit patterns). With these 16 patterns you can convert any binary ↔ hex instantly, and the first 8 (3-bit) patterns give you binary ↔ octal.

Number systems in Python

Python has built-in functions to see a number in other bases: bin(), oct(), hex(). The prefixes 0b, 0o, 0x tell which base it is. int(text, base) converts back to decimal.

Python
n = 45
print(bin(n))     # binary
print(oct(n))     # octal
print(hex(n))     # hexadecimal
print(int('101101', 2), int('55', 8), int('2D', 16))
0b101101 0o55 0x2d 45 45 45

You can also write numbers directly in these bases: 0b1010 is 10, 0o17 is 15 and 0xFF is 255.

Summary & practice

  • Base = number of digits: decimal 10, binary 2, octal 8, hexadecimal 16.
  • Value = Σ digit × baseposition, position starting at 0 from the right.
  • 1 octal digit = 3 bits; 1 hex digit = 4 bits.
  • Python: bin(), oct(), hex(), int(s, base).
✅ Practice

1) Which of these is not a valid octal number: 175, 382, 66? 2) What is the decimal value of (1F)₁₆? 3) How many bits are needed to write the hex number 3A9?

Answers: 1) 382 (digit 8 is not allowed). 2) 31. 3) 3 hex digits × 4 = 12 bits.

Frequently Asked Questions

Why is hexadecimal used if computers work in binary?
Long binary numbers are hard for people to read. One hex digit stands for exactly 4 bits, so 11111111 becomes just FF. It is used for colour codes, memory addresses and MAC addresses.
What is the base of the octal number system?
The base is 8 and the digits are 0 to 7. One octal digit stands for exactly 3 bits.
How do we write the base of a number?
As a subscript, for example (1011)₂ for binary, (17)₈ for octal, (25)₁₀ for decimal and (1F)₁₆ for hexadecimal.
← Class 11 Computer Science
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicNumber System Conversions Your progress: 4 / 29 (14%) · Lesson 5 / 29 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free