Lesson 4.1: Binary, Denary and Hexadecimal
Introduction
Welcome to Lesson 4.1 on Binary, Denary, and Hexadecimal! 🤖 In this lesson, we will unlock the mysteries of how computers represent information. By the end of this lesson, you will understand why computers use binary, how to convert between different number systems, and how to perform binary addition. Let’s dive in!
Learning Objectives
By the end of this lesson, students should be able to:
- Explain why computers use binary, along with understanding bits, nibbles, bytes, and units of storage (kB, MB, GB).
- Convert numbers between denary, binary, and hexadecimal systems.
- Understand the purpose of hexadecimal as a compact form of binary.
- Perform binary addition and understand overflow.
- Convert whole numbers between denary, binary, and hexadecimal.
What is Binary?
Binary is a base-2 number system that uses only two digits: 0 and 1. 🟡🟢 Each digit in a binary number is known as a bit. Here’s how binary works:
- Bit: The smallest unit of data in a computer, either 0 or 1.
- Nibble: 4 bits (for example, 1001).
- Byte: 8 bits (for example, 11001010).
- Kilobyte (kB): 1024 bytes.
- Megabyte (MB): 1024 kB.
- Gigabyte (GB): 1024 MB.
Computers use binary because electronic circuits have two states: on (1) and off (0). This allows computers to process data efficiently and reliably.
Understanding Denary, Binary, and Hexadecimal
The denary (or decimal) system is what we typically use, based on 10 digits (0-9). To convert between denary and binary, you may follow these steps:
Example: Converting Denary to Binary
Let’s take the denary number 13.
- Start with the largest power of 2 less than 13 (which is $2^3 = 8$).
- Subtract 8: $13 - 8 = 5$.
- The next largest power of 2 in 5 is $2^2 = 4$.
- Subtract 4: $5 - 4 = 1$.
- The last number is $2^0 = 1$.
Binary representation: 1101, which corresponds to:
- $2^3$ + $2^2$ + 0 + $2^0$
Example: Converting Binary to Denary
To convert the binary number 1011 to denary:
- Start from the right, multiplying each bit by $2$ raised to the power of its position, starting from 0:
- $1 \times 2^3 = 8$
- $0 \times 2^2 = 0$
- $1 \times 2^1 = 2$
- $1 \times 2^0 = 1$
- Add them up: $8 + 0 + 2 + 1 = 11$.
Hexadecimal System
Hexadecimal (base-16) is often used in computing because it is more compact than binary. Hexadecimal uses 16 symbols: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15).
Example: Converting Binary to Hexadecimal
To convert 11010110 to hexadecimal:
- Group the binary number in sets of four from the right: 1101 0110.
- Convert each group to denary:
- 1101 = 13 (D in hex)
$ - 0110 = 6.$
- Combine the result: D6 in hexadecimal.
Why Hexadecimal?
Hexadecimal is compact and easier for humans to read compared to long binary numbers. For example:
- Binary: 11111111
- Hexadecimal: FF
Using hexadecimal makes it simpler for programmers to read and write code, especially in memory addresses and color codes in web design! 🎨
Binary Arithmetic
Just like in denary, we can perform addition in binary. Here’s how it works:
Example: Binary Addition
Let’s add 1011 (11 in denary) and 1101 (13 in denary).
1011
+ 1101
-------
11000 (This is 24 in denary)
In binary addition, remember:
- $0 + 0 = 0$
- $1 + 0 = 1$
- $1 + 1 = 10$ (This is where overflow occurs!)
- $1 + 1 + 1 = 11$ (where we carry over 1).
Overflows in Binary Operations
An overflow occurs when the result of an operation exceeds the range that can be represented with a given number of bits. For example, in an 8-bit system, if you try to add 255 (11111111 in binary) and 1, you don't get 256 (which requires 9 bits), but rather 0 (as it wraps around).
Conclusion
Congratulations, students! 🎉 You have now learned about binary, denary, hexadecimal, and binary arithmetic! Understanding these concepts is crucial for anyone interested in computing and programming.
Study Notes
- Binary uses bits (0 and 1) for data representation.
- Nibble = 4 bits; Byte = 8 bits; kB = 1024 bytes; MB = 1024 kB; GB = 1024 MB.
- Denary is a base-10 system, while binary is base-2 and hexadecimal is base-16.
- We can convert between denary, binary, and hexadecimal using specific methods.
- Binary addition follows unique rules and can result in overflow when the result exceeds the bit limit.
