Computer Number System
What is Number Systems?
In computers, number systems are fundamental. They allow us to represent values in a way that computers can understand.
There are primarily two types of number systems: positional and non-positional.
Positional Number Systems
- In a positional number system, the position of a digit matters.
- The decimal system (base 10) is the most common positional number system.
In the base 10 numbering system:
- Ones: The rightmost digit represents the number of ones. For example, in the number 123, the '3' stands for 3 ones.
- Tens: Moving one position to the left, the next digit represents the number of tens. In the number 123, the '2' stands for 2 tens.
- Hundreds: Going one more position to the left, the leftmost digit represents the number of hundreds. In the number 123, the '1' stands for 1 hundred.
Non-positional Number Systems
- Non-positional number systems don't rely on the position of digits.
- Each digit has a fixed value, regardless of its position. An example of a non-positional number system is the Roman numeral system (I, V, X, etc.).
- In Roman numerals, 'V' always represents 5, no matter where it is in the number.
Now, let's talk about some commonly used positional number systems in computing:
Binary (Base 2)
- The binary system is a way of counting and representing numbers using just two digits: 0 and 1.
- Each digit's position represents a power of 2. For example, in the binary number 1101, the '1's represents 8, 4, and 1, while the '0' represents 0.
- So, it's equivalent to 8 + 4 + 0 + 1 = 13 in decimal.
Octal (Base 8) and Hexadecimal (Base 16)
- Octal is a base-8 number system, using digits from 0 to 7.
- Hexadecimal is a base-16 number system, using digits 0-9 and letters A- F to represent values 10-15.
- They are often used in computing for their convenience in representing binary values.
Inter-conversion of Number Systems
Converting between number systems is essential in computing:
Binary to Decimal
- To convert a binary number to decimal, multiply each digit by 2 raise to the power of its position, and add them up.
- For example, to convert 1101 to decimal: (1 * 2^3) + (1 * 2^2) + (0 * 2^1) + (1 * 2^0) = 8 + 4 + 0 + 1 = 13.
Decimal to Binary
- To convert a decimal number to binary, you repeatedly divide by 2 and record the remainder.
- Then, reverse the remainder to get the binary equivalent. For instance, to convert 13 to binary:
- 13 ÷ 2 = 6 remainder 1
- 6 ÷ 2 = 3 remainder 0
- 3 ÷ 2 = 1 remainder 1
- 1 ÷ 2 = 0 remainder 1
So, the binary equivalent is 1101.
Binary Arithmetic
Binary arithmetic involves performing mathematical operations in binary:
Binary Addition
Binary addition works just like decimal addition.
1 1101
2+ 1010
3-------
4 11011
Carry is carried over when the sum exceeds 1.
Binary Subtraction
Binary subtraction also resembles decimal subtraction.
1 1101
2- 1010
3-------
4 011
If you can't subtract a digit, you borrow from the next higher position.
Binary Multiplication
Binary multiplication is like decimal multiplication, using 0 and 1 as multipliers.
1 1101
2x 101
3-------
4 1101
5 0000
61101
7-------
8111101
Multiply each digit in the first number by each digit in the second, shifting left for each new row.
Binary Division
- The binary division is like dividing numbers in our everyday decimal system, but instead of using ten digits (0 through 9), we use only two digits, 0 and 1.
- Divide the leftmost bits, subtract the divisor, and bring down the next bit.
Using Complements for Negative Binary Numbers
To represent negative binary numbers, we use complements. There are two common types:
1's Complement
In the 1's complement, flip all its bits to negate a binary number (0s become 1s, and vice versa).
1 Positive: 1101
2 1's Complement: 0010
2's Complement
In the 2's complement, negate a binary number by flipping bits and adding 1 to the result.
1 Positive: 1101
2 2's Complement: 0011
Subtraction Using Complements
- Subtraction using 1's complement is equivalent to addition. Subtracting binary numbers A and B is the same as adding A to the 1's complement of B.
- Subtraction using 2's complement is similar, but there's no need to add 1.
What is BCD (Binary Coded Decimal)?
- Binary Coded Decimal (BCD) is a way of representing decimal numbers using binary encoding.
- In BCD, every decimal digit is shown using a 4-bit binary code.
- This encoding makes it easy to perform arithmetic operations and conversions between binary and decimal.
What is ASCII?
- ASCII, which stands for American Standard Code for Information Interchange, is a character encoding standard that represents text and control characters using 7-bit binary codes.
- It was originally developed in the 1960s and has become the basis for many character encoding systems used in computers and communication devices.
What is EBCDIC?
- EBCDIC, which stands for Extended Binary Coded Decimal Interchange Code, is another character encoding standard.
- Unlike ASCII, which uses 7-bit codes, EBCDIC uses 8-bit codes to represent characters.
- EBCDIC was primarily developed by IBM and was widely used in their mainframe and early computing systems.
Conclusion
In computing, number systems are foundational for representing values, with positional and non-positional number systems being the two main categories.