Binary Number Systems
COS2621 - Computer Organisation · Digital Logic Design
Binary Number Systems
The binary number system uses only two digits, 0 and 1, to represent values. This system is the foundation of all modern computing. Understanding binary is essential for working with digital logic, machine code, and assembly language programming.
Understanding Binary Representation
In the binary system, each digit is called a bit. A group of eight bits is known as a byte. Each position in a binary number represents a power of 2, similar to how each position in a decimal number represents a power of 10.
For example, the binary number 1011 can be understood as follows:
1 × 2^3 + 0 × 2^2 + 1 × 2^1 + 1 × 2^0This can be calculated step by step:
- 1 × 2^3 = 8
- 0 × 2^2 = 0
- 1 × 2^1 = 2
- 1 × 2^0 = 1
Now, add these values together:
8 + 0 + 2 + 1 = 11Thus, the binary number 1011 is equal to the decimal number 11.
Remember: Each bit represents a power of 2, starting from the right with 2^0.
Converting Decimal to Binary
To convert a decimal number to binary, you can use the division by 2 method. This involves repeatedly dividing the decimal number by 2 and recording the remainders.
For example, to convert 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 1
Now, write the remainders in reverse order:
1101Thus, the decimal number 13 is equal to the binary number 1101.
Watch out: Always write the remainders in reverse order; this is a common mistake.
Converting Binary to Decimal
To convert a binary number back to decimal, you can use the method of multiplying each bit by its corresponding power of 2. For example, to convert the binary number 1101 to decimal:
1 × 2^3 + 1 × 2^2 + 0 × 2^1 + 1 × 2^0Calculating this gives:
- 1 × 2^3 = 8
- 1 × 2^2 = 4
- 0 × 2^1 = 0
- 1 × 2^0 = 1
Now, add these values together:
8 + 4 + 0 + 1 = 13Thus, the binary number 1101 is equal to the decimal number 13.
Binary Arithmetic
Binary arithmetic follows the same principles as decimal arithmetic, but it only uses two digits. The basic operations are addition, subtraction, multiplication, and division.
Binary Addition
Binary addition works similarly to decimal addition. The key points to remember are:
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (which is 0 with a carry of 1)
- 1 + 1 + 1 = 11 (which is 1 with a carry of 1)
For example, to add the binary numbers 1011 and 1101:
1011
+ 1101
-------Add from right to left:
- 1 + 1 = 10 (write down 0, carry 1)
- 1 + 0 + 1 (carry) = 10 (write down 0, carry 1)
- 0 + 1 + 1 (carry) = 10 (write down 0, carry 1)
- 1 + 1 + 1 (carry) = 11 (write down 1, carry 1)
Finally, write down the carry:
1
1011
+ 1101
-------
11000Thus, 1011 + 1101 = 11000 in binary, which is 24 in decimal.
Tip: Practice binary addition with different numbers to become comfortable with the process.
Binary Subtraction
Binary subtraction also follows similar rules as decimal subtraction. The key points are:
- 0 - 0 = 0
- 1 - 0 = 1
- 1 - 1 = 0
- 0 - 1 requires borrowing
For example, to subtract the binary number 1101 from 1011:
1011
- 1101
-------Since 1011 is smaller than 1101, we need to borrow:
- Borrow from the leftmost bit (which becomes 0), making the second bit from the left 2 (or 10 in binary).
- Now, we can perform the subtraction:
0 10 1
1011
- 1101
-------
0010Thus, 1011 - 1101 = 0010 in binary, which is 2 in decimal.
Binary Multiplication
Binary multiplication is similar to decimal multiplication. You multiply each bit of the first number by each bit of the second number. For example, to multiply 101 by 11:
101
× 11
-------Multiply each bit of 101 by 1, then by 1 (shift left for each new row):
101
× 11
-------
101
1010
-------Now, add the results:
101
+1010
-------
1111Thus, 101 × 11 = 1111 in binary, which is 15 in decimal.
Binary Division
Binary division is similar to decimal long division. For example, to divide 1100 by 11:
11 | 1100
-------Determine how many times 11 fits into the first bits of 1100. It fits 1 time:
11 | 1100
- 11
-------
0010Now, bring down the next bit:
11 | 1100
- 11
-------
00100
- 00
-------
010011 fits into 100, so it fits 1 time:
11 | 1100
- 11
-------
00100
- 00
-------
0100
- 11
-------
001The result is 10 with a remainder of 1. Thus, 1100 ÷ 11 = 10 in binary, which is 2 in decimal.
Binary Number Systems in Computing
Binary numbers are crucial in computing. Computers use binary to process data and execute instructions. Each instruction and data type in programming languages is represented in binary format. Understanding binary number systems helps in understanding how computers work at a fundamental level.
Remember: All data in computers is ultimately represented in binary.
Summary
- The binary number system uses only 0 and 1.
- Each bit represents a power of 2.
- To convert decimal to binary, use the division by 2 method.
- To convert binary to decimal, use powers of 2.
- Binary arithmetic includes addition, subtraction, multiplication, and division.
Check your understanding
- What is the binary representation of the decimal number 25?
- Convert the binary number 1010 to decimal.
- Add the binary numbers 1100 and 1010.
- Subtract the binary number 1001 from 1110.