Skip to content

04-21: Number System Explorer

Python: Fundamentals

View the live site — ijk37.com

Project 21

Home  |  All Projects  |  Notes  |  Exercises  |  Quiz Hub

Converts numbers between decimal, binary, octal, and hexadecimal using built-ins (bin(), oct(), hex(), int(x, base)) and a manual algorithm. Also demonstrates bitwise operators (&, |, ^, ~, <<, >>) and the math module.

Topics covered: bin() · oct() · hex() · int(string, base) · bitwise operators · math.sqrt/log2/gcd/lcm/factorial · manual base-conversion algorithm

Difficulty: ⭐⭐ Beginner–Intermediate


How to Run

python main.py

Sample: Conversion Table (0–5)

  Dec  Binary        Octal     Hex
  ──────────────────────────────────
    0  0             0         0
    1  1             1         1
    2  10            2         2
    3  11            3         3
    4  100           4         4
    5  101           5         5

Key Concepts Practised

Concept Where used
bin(n)[2:] Strip "0b" prefix
int("1010", 2) Binary string → decimal
n % 2 / n // 2 Manual binary algorithm
a & b, a \| b, a ^ b Bitwise AND/OR/XOR
a << 1 Left shift (×2)
math.gcd(a, b) Greatest common divisor