Number Systems and Data Representation With easy examples.
A number system is a way of writing numbers using a fixed set of digits and a base (radix). Decimal uses base 10 with digits 0-9, binary uses base 2 with digits 0-1, octal uses base 8, and hexadecimal uses base 16 with digits 0-9 plus A-F. Data representation is how computers store numbers, text, and everything else as patterns of binary digits — because transistors naturally have two stable states, on and off.
Every byte of memory, every network address, and every pixel color is a binary pattern wearing a human-friendly mask. Programmers read memory dumps in hex, network engineers read IP addresses as binary groups, and two's complement explains why adding 1 to the largest integer wraps around to a negative number.
Key Concepts
- Positional value: in base b, each digit is multiplied by a power of b based on its position from the right, starting at b to the power 0.
- Binary (base 2): the machine's native language; 8 bits form a byte.
- Hexadecimal (base 16): compact shorthand — one hex digit equals exactly 4 bits, used for addresses and color codes.
- Two's complement: the standard signed-integer storage: negate by inverting all bits and adding 1.
- IEEE 754 floating point: the standard for real numbers, splitting 32 or 64 bits into sign, exponent, and fraction fields.
Formulas
- Positional value: value = d_n x b^n + … + d_1 x b^1 + d_0 x b^0, where d_i are the digits and b is the base.
- Two's complement negation: -x = (bitwise NOT of x) + 1.
- Signed n-bit range: from -2^(n-1) to 2^(n-1) - 1. For 8 bits: -128 to 127. For 32 bits: -2,147,483,648 to 2,147,483,647.
- Bits needed: values 0 to N need ceiling(log2(N+1)) bits; 0-255 needs exactly 8 bits.
Worked Example
Convert 101101 in binary to decimal and hex, then find the 8-bit two's complement of -13:
- Positional expansion: 1x2^5 + 0x2^4 + 1x2^3 + 1x2^2 + 0x2^1 + 1x2^0 = 32 + 0 + 8 + 4 + 0 + 1 = 45.
- To hex, group in fours: 0010 1101 → 2 and D → 2D. Check: 2x16 + 13 = 45.
- Two's complement of -13: +13 = 00001101. Invert → 11110010. Add 1 → 11110011.
- Verify: 11110011 = 128 + 64 + 32 + 16 + 2 + 1 = 243; as signed 8-bit, 243 - 256 = -13.
Common Misconceptions
- Computers store decimal numbers. They store binary patterns; decimal appears only when software converts patterns for display.
- More bits just means bigger numbers. More bits also mean finer fractional precision and larger address spaces.
- 0.1 + 0.2 equals 0.3 in a computer. In binary floating point it is 0.30000000000000004 — 0.1 has no exact binary representation, a classic money-calculation bug.
Real-World Applications
- Memory and addresses: debuggers and dumps display bytes in hexadecimal.
- Networking: IPv4 addresses are four 8-bit groups; subnet masks are read as binary.
- Graphics: colors like #FF5733 are hex triplets of red, green, and blue bytes.
- File sizes: kilobytes and megabytes are powers of two (1024-based) because of binary addressing.
Number systems bridge human-friendly digits and the binary reality of hardware. Master positional notation, two's complement, and hex shorthand, and memory dumps, IP addresses, and color codes stop being mysterious — the same binary patterns, written in different bases.
Related blogs
- ALU Design and Datapath: Complete Beginner's Guide
- Instruction Set Architecture (ISA) With easy examples.
- Pipelining and Hazards in Processors With easy examples.
- Cache Memory and Memory Hierarchy: Complete Beginner's Guide
- I/O organization and interrupts Explained with Examples
- RISC vs CISC Architectures: Complete Beginner's Guide