Lesson 05
High-Level Programming
Low-level vs high-level languages, and working with bin/oct/hex in Python.
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(), andhex()?
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
a = 0b1010101010 # Binary
b = 0xBEE # Hexadecimal
c = 0o23 # OctalThese prefixes tell Python which number system you're using.
Number Systems Overview
| 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
a = 0b1010
b = 0xA
c = 0o12
print(a)
print(b)
print(c)Output:
10
10
10Why?
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).
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
a = 0b1010 # Binary 10
b = 0xA # Hexadecimal 10
c = 0o12 # Octal 10
print(a)
print(b)
print(c)
print(a + b + c)Output:
10
10
10
30Visual comparison
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
print(bin(22000))
print(hex(3054))
print(oct(64))Possible output:
0b101010111110000
0xbee
0o100Conversion flow
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.
binary = 0b1111
octal = 0o20
hexadecimal = 0x10
print(binary)
print(octal)
print(hexadecimal)
print(binary + octal + hexadecimal)Expected output:
15
16
16
47Challenge
Convert the decimal number 255 into:
- Binary
- Octal
- Hexadecimal
Try using:
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(), andhex()convert decimal numbers into other number systems.- Python hides machine-level complexity through byte code and the Python Virtual Machine (PVM).
Interview Questions
- What is the difference between a low-level and a high-level language?
- Why is Python called a high-level language?
- What do the prefixes
0b,0o, and0xrepresent? - Which function converts a decimal number to hexadecimal?
- 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.