Courses / Physics I
Computer Science

Data representation and basic types

Physics I 205 words Free to read

Number Systems & Bases

Computers represent all data as binary (base 2). Understanding how numbers are encoded prevents bugs in scientific computing.

BaseNameDigitsExample (131013_{10})
2Binary0, 1110121101_2
10Decimal0–9131013_{10}
16Hexadecimal0–9, A–FD16\text{D}_{16}

Conversion formula: 11012=123+122+021+120=13101101_2 = 1\cdot2^{3} + 1\cdot2^{2} + 0\cdot2^{1} + 1\cdot2^{0} = 13_{10}.

Basic Python types:

Floats, Conversion & Pitfalls

Floating-point caution: Not all decimals are exact in binary representation.

>>> 0.1 + 0.2
0.30000000000000004

Common pitfall: Floats are not real numbers. Compare numerical results using a tolerance (abs(a - b) < 1e-9), never with ==, or your simulation will fail due to pure representation artifacts.

Type conversion:

Physics link: Watch for integer division (5 // 2 = 2) versus float division (5 / 2 = 2.5) to avoid off-by-one errors.

Ten additions of 0.1 do not reach 1.0, and == cannot tell them apart

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

13practice questions
2interactive scenes

Computer Science