9.3 The Binary System
COS2621 - Computer Organisation · 9. Number Systems
The Binary System
Introduction to Binary
The binary system is a base-2 numeral system that uses only two digits: 0 and 1. This system is fundamental to computer systems because digital electronics operate using two states, represented as OFF (0) and ON (1). Each digit in a binary number is called a bit.
Understanding Bits and Bytes
A single bit can represent two values (0 or 1). Eight bits make a byte, which can represent 256 different values (from 0 to 255). For example, the binary number 11010101 represents the decimal number 213.
Remember: 1 byte = 8 bits.
Positional Value in Binary
Each position in a binary number represents a power of 2, starting from the right. The rightmost bit represents 2^0, the next represents 2^1, then 2^2, and so on. For example, the binary number 1011 can be calculated as:
1 × 2^3 + 0 × 2^2 + 1 × 2^1 + 1 × 2^0 = 8 + 0 + 2 + 1 = 11Example of Binary Representation
Consider the binary number 11010. Its decimal equivalent is calculated as:
1 × 2^4 + 1 × 2^3 + 0 × 2^2 + 1 × 2^1 + 0 × 2^0 = 16 + 8 + 0 + 2 + 0 = 26Converting Decimal to Binary
To convert a decimal number to binary, repeatedly divide the number by 2 and record the remainder. For example, converting the decimal number 13 to binary:
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1Reading the remainders from bottom to top gives us 1101, so 13 in decimal is 1101 in binary.
Watch out: Always read remainders from bottom to top when converting.
Binary Arithmetic
Binary arithmetic follows the same rules as decimal arithmetic but only uses the digits 0 and 1. For example, adding two binary numbers:
1101 (13 in decimal)
+ 1011 (11 in decimal)
-------
11000 (24 in decimal)Converting Hexadecimal to Binary
Hexadecimal numbers use base-16 and include digits 0-9 and letters A-F. To convert hexadecimal to binary, convert each hex digit to its 4-bit binary equivalent. For example, converting C7AEh:
C = 1100
7 = 0111
A = 1010
E = 1110Thus, C7AEh in binary is 1100011110101110.
Example Problem
Consider the hexadecimal addition 1Fh + 9Ch. To solve this:
1Fh = 31 in decimal
9Ch = 156 in decimal
31 + 156 = 187 in decimal
187 in hexadecimal is BBh.The result of the addition is BBh.
Summary
- The binary system uses only two digits: 0 and 1.
- Each bit represents a power of 2.
- Conversions between binary and decimal involve division and remainder for decimal to binary, and summation of powers for binary to decimal.
Check your understanding
- What is the binary representation of the decimal number 25?
- How many bits are in a byte?
- Convert the binary number 101011 to decimal.
- What is the result of adding the binary numbers 1010 and 1101?
Test yourself
5 quick questions on this lesson. Pick an answer to see if you're right.
1. Which one of the following statements is false when we are talking about ASCII encodings?
2. What is the binary representation of the decimal number 25?
3. How many bits are in a byte?
4. What is the result of adding the binary numbers 1010 and 1101?
5. Convert the binary number 101011 to decimal.