Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 05

High-Level Programming

Low-level vs high-level languages, and working with bin/oct/hex in Python.

Beginner10 min

What you will learn

By the end of this lesson, you'll understand:

  • What is the difference between low-level and high-level programming languages?
  • Why is Python considered a high-level language?
  • How does Python handle binary, octal, and hexadecimal numbers?
  • How do you convert numbers using bin(), oct(), and hex()?

What is a High-Level Language?

Programming languages are generally divided into two categories.

Low-Level Language

  • Close to hardware
  • Uses binary, registers, memory
  • Harder for humans to read
  • More machine-oriented

High-Level Language

  • Close to human language
  • Easy syntax
  • Automatic memory management
  • More programmer-friendly

Python belongs to the High-Level category.

Low-Level Programming

Low-level programming works with machine-friendly number systems such as:

  • Binary (Base 2)
  • Octal (Base 8)
  • Hexadecimal (Base 16)

Example literals

python
a = 0b1010101010   # Binary
b = 0xBEE          # Hexadecimal
c = 0o23           # Octal

These prefixes tell Python which number system you're using.

Number Systems Overview

Binary, octal, decimal, and hex prefixes
System Prefix Base
Binary 0b 2
Octal 0o 8
Decimal (none) 10
Hexadecimal 0x 16

High-Level Programming in Python

Even if you write numbers in binary, octal, or hexadecimal…

Python displays them as decimal by default.

Example

python
a = 0b1010
b = 0xA
c = 0o12

print(a)
print(b)
print(c)

Output:

text
10
10
10

Why?

Because Python assumes humans understand decimal more easily than binary or hexadecimal.

How Python Executes Your Code

Your source notes explain that Python converts high-level instructions into byte code, which is executed by the Python Virtual Machine (PVM).

Python source to byte code to PVM

Key idea

  • You write readable Python code.
  • Python converts it into byte code.
  • The PVM executes that byte code.

You do not manage processor instructions or registers yourself.

Working with Binary, Octal & Hexadecimal

Example 1 — Different literals, same value

python
a = 0b1010      # Binary 10
b = 0xA         # Hexadecimal 10
c = 0o12        # Octal 10

print(a)
print(b)
print(c)
print(a + b + c)

Output:

text
10
10
10
30

Visual comparison

0b1010, 0o12, and 0xA all equal decimal 10

Although the notation is different, the stored value is identical.

Converting Decimal to Other Number Systems

Python provides built-in conversion functions.

Function Converts to
bin() Binary
oct() Octal
hex() Hexadecimal

Example

python
print(bin(22000))
print(hex(3054))
print(oct(64))

Possible output:

text
0b101010111110000
0xbee
0o100

Conversion flow

Decimal 22000 through bin() to binary text

These functions return the text representation of the number.

Why This Matters in AI & Software Engineering

You won't often write binary numbers manually, but you'll frequently encounter hexadecimal values in:

Area Example
Colors #FF5733
Memory Addresses & debugging
Networking Packet analysis
Cybersecurity Hex dumps
Embedded Systems Binary operations

Python lets you work with these formats without dealing directly with machine code.

Practice Exercise

Store one value in each number system.

python
binary = 0b1111
octal = 0o20
hexadecimal = 0x10

print(binary)
print(octal)
print(hexadecimal)
print(binary + octal + hexadecimal)

Expected output:

text
15
16
16
47

Challenge

Convert the decimal number 255 into:

  • Binary
  • Octal
  • Hexadecimal

Try using:

python
bin(255)
oct(255)
hex(255)

Key Points

  • Python is a high-level programming language.
  • It accepts binary (0b), octal (0o), and hex (0x) literals.
  • Numbers are displayed in decimal by default.
  • bin(), oct(), and hex() convert decimal numbers into other number systems.
  • Python hides machine-level complexity through byte code and the Python Virtual Machine (PVM).

Interview Questions

  1. What is the difference between a low-level and a high-level language?
  2. Why is Python called a high-level language?
  3. What do the prefixes 0b, 0o, and 0x represent?
  4. Which function converts a decimal number to hexadecimal?
  5. What is the role of the Python Virtual Machine (PVM)?

Summary

Concept Remember
Low-Level Machine-oriented programming
High-Level Human-readable programming
Binary Prefix 0b
Octal Prefix 0o
Hex Prefix 0x
Decimal → Binary bin()
Decimal → Octal oct()
Decimal → Hex hex()
Execution Byte Code → PVM

Python's strength is that it accepts low-level numeric formats while letting you program at a high level, making software easier to write, read, and maintain.

Next

Next lesson: Interpreted Programming Language — how Python executes .py files, what an interpreter is, and how the PVM runs your programs line by line.