Unit1: Number systems
Unit1: Number systems
Number systems are mathematical systems used to represent and manipulate numbers. They are essential in computing, mathematics, and various fields of science and engineering. Four common number systems are binary, octal, decimal, and hexadecimal. Each of these systems uses a different base to represent numbers and has its own unique characteristics.
Binary Number System (Base-2):
Base: Binary is a base-2 number system, which means it uses only two digits: 0 and 1.
Representation: In binary, numbers are represented as sequences of 0s and 1s. Each digit in a binary number is called a "bit."
Usage: Binary is fundamental in computing because digital computers use binary logic (0s and 1s) to perform calculations and store data.
Octal Number System (Base-8):
Base: Octal is a base-8 number system, which means it uses eight digits: 0 to 7.
Representation: Octal numbers are represented using digits 0-7. Each digit in an octal number represents three bits of binary information.
Usage: Octal is not as commonly used today but was more prevalent in early computer systems for its compatibility with binary representations.
Decimal Number System (Base-10):
Base: Decimal is the base-10 number system, which means it uses ten digits: 0 to 9.
Representation: Decimal numbers are what we commonly use in everyday life. They are represented using digits 0-9, and each digit's position represents a power of 10.
Usage: Decimal is the most familiar number system used by humans for everyday calculations, such as arithmetic, money, and measurements.
Hexadecimal Number System (Base-16):
Base: Hexadecimal is a base-16 number system, which means it uses sixteen digits: 0 to 9 and A to F (or a to f for lowercase letters).
Representation: Hexadecimal numbers use a combination of digits and letters. Each digit in a hexadecimal number represents four bits of binary information.
Usage: Hexadecimal is commonly used in computer programming and digital systems to represent binary data more compactly and to make it easier for humans to read and work with large binary values.
In summary, number systems are ways to represent and work with numbers using different bases and sets of digits. Each system has its own strengths and use cases, with binary being fundamental in computing, decimal being the most common for everyday use, octal being historically significant, and hexadecimal being widely used in programming and digital systems.
Conversion of numbers
1. Binary, Octal, and Hexadecimal to Decimal:
Binary to Decimal: To convert a binary number to decimal, multiply each digit by the corresponding power of 2 (starting from the right and increasing by 1 for each digit), and sum them up.
Example: Convert binary 101010 to decimal.
= 1 * 2^5 + 0 * 2^4 + 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 0 * 2^0
= 32 + 0 + 8 + 0 + 2 + 0
= 42
Octal to Decimal: To convert an octal number to decimal, multiply each digit by the corresponding power of 8 (starting from the right and increasing by 1 for each digit), and sum them up.
Example: Convert octal 63 to decimal.
= 6 * 8^1 + 3 * 8^0
= 48 + 3
= 51
Hexadecimal to Decimal: To convert a hexadecimal number to decimal, multiply each digit by the corresponding power of 16 (starting from the right and increasing by 1 for each digit), and sum them up.
Example: Convert hexadecimal 1A7 to decimal.
= 1 * 16^2 + 10 * 16^1 + 7 * 16^0
= 256 + 160 + 7
= 423
2. Decimal to Binary:
To convert a decimal number to binary, you can repeatedly divide the decimal number by 2 and record the remainders until the quotient becomes zero. Then, write down the remainders in reverse order.
Example: Convert decimal 27 to binary.
Step 1: 27 ÷ 2 = 13 remainder 1 (LSB)
Step 2: 13 ÷ 2 = 6 remainder 1
Step 3: 6 ÷ 2 = 3 remainder 0
Step 4: 3 ÷ 2 = 1 remainder 1
Step 5: 1 ÷ 2 = 0 remainder 1 (MSB)
So, the binary representation of 27 is 11011.
3. Octal and Hexadecimal to Binary:
Octal to Binary: To convert an octal number to binary, replace each octal digit with its binary equivalent.
Example: Convert octal 63 to binary.
6 -> 110
3 -> 011
So, octal 63 in binary is 110011.
Hexadecimal to Binary: To convert a hexadecimal number to binary, replace each hexadecimal digit with its 4-bit binary equivalent.
Example: Convert hexadecimal 1A7 to binary.
1 -> 0001
A -> 1010
7 -> 0111
So, hexadecimal 1A7 in binary is 000110100111.
Binary arithmetic Operation: addition, subtraction, multiplication and division
1. Binary Addition:
Binary addition is straightforward, just like decimal addition. You add binary digits from right to left, carrying over when the sum exceeds 1. Here's an example:
1101
+ 1011
---------
11000
In this example, we start from the rightmost digits (1 + 1), which equals 10 in binary. We write down the 0 and carry over the 1. Then, we add the next digits, including the carry (1 + 1 + 1), which also equals 10 in binary, so we write down 0 and carry over the 1 again. This process continues until we have added all the digits.
Binary Addition Rules:
1 + 1 = 0 with a carry of 1: When adding two 1s in binary, the result is 0, and a carry of 1 is generated. This is similar to carrying over to the next place value in decimal addition when the sum exceeds 9.
1 + 0 = 1: When adding 1 to 0 in binary, the result is 1.
0 + 1 = 1: When adding 1 to 0 in binary, the result is 1.
0 + 0 = 0: When adding two 0s in binary, the result is 0.
2. Binary Subtraction:
Binary subtraction is also similar to decimal subtraction. You start from the right and borrow when needed. Here's an example:
1101
- 1011
---------
110
In this example, we start from the rightmost digits (1 - 1), which equals 0 in binary. Then, we subtract the next digits. When we encounter a situation where we need to borrow, we borrow from the next higher digit (just like in decimal subtraction).
Binary Subtraction Rules:
0 - 0 = 0: When subtracting 0 from 0 in binary, the result is 0.
1 - 0 = 1: When subtracting 0 from 1 in binary, the result is 1.
1 - 1 = 0: When subtracting 1 from 1 in binary, the result is 0.
0 - 1 with borrowing = 1: When subtracting 1 from 0 in binary, you need to borrow from the next higher place value. This is similar to borrowing in decimal subtraction.
3. Binary Multiplication:
Binary multiplication is performed similarly to decimal multiplication, where you multiply each digit of one binary number by each digit of the other binary number and then add the results.
Here's an example of multiplying 1101 by 1011:
1101
x 1011
---------
1101 (1101 multiplied by 1)
0000 (1101 multiplied by 0, shift one position to the left)
1101 (1101 multiplied by 1, shift two positions to the left)
1101 (1101 multiplied by 1, shift three positions to the left)
---------
10001111
Binary Multiplication Rules:
0 * (any number) = 0: When multiplying any number by 0 in binary, the result is 0.
1 * 0 = 0: When multiplying 1 by 0 in binary, the result is 0.
1 * 1 = 1: When multiplying 1 by 1 in binary, the result is 1.
4. Binary Division:
Binary division is similar to decimal division but uses binary digits. Here's an example of dividing 10001111 by 1011:
1111
---------------
1011 | 10001111
-1011
---------------
10010
-1011
---------------
1001
-1011
---------------
100
In this example, we perform long division just as we would in decimal, but with binary digits.
Binary Division Rules:
0 / (any number except 0) = 0: When dividing 0 by any nonzero number in binary, the result is 0.
(any number except 0) / 0 is undefined: Division by 0 is undefined in binary, just as it is in decimal.
0 / 0 is undefined: Division by 0 is undefined in binary, just as it is in decimal.
Remember that carrying, borrowing, and shifting are key concepts in binary arithmetic, just like in decimal arithmetic. With practice, these operations become more intuitive in binary as well.