Lecture 4 Numbersystem
Lecture 4 Numbersystem
Number systems:
• Number system is a way to represent numbers
• To a computer everything is a number, letters punctuation sound pictures etc.
• A set of values used to represent different quantities is known as number system.
• Total number of digits used in a number system is called its base or radix
• The radix or base is the number of unique digits, including zero, used to represent
numbers in a positional numeral system. For example, for the decimal system (the most
common system in use today) the radix is ten, because it uses the ten digits from 0
through 9.
o Written after number as a subscript e.g. (256)10
• Important number systems are as follows
o Binary number system
o Decimal number system
o Octal number system
o Hexadecimal number system
• LSB least significant bit
o Is the digit in a number that has the least effect on that number
o Any change in LSD will have minimal effect the value
o Non zero digit
o Farthest right
• MSB (most significant bit)
o is the digit in a number which can affect the number significantly
o the value of the number having the greatest amount is either increased or
decreased.
o Non zero digit of a number
o Farthest left
e.g. in number 45356 4 is MSB and 6 is LSB
1.1 Binary number system
• Digital computer represents all kinds of data and information in binary system
• Base/ radix is 2, and The two digits are "0" and "1"
• Important terms used in binary numbers are
o Bit: smallest possible unit of data
o Byte: group of 8 bits
o Nibble: 4 bits, half byte
o Word :2 bytes, 16 bits
o With n bits we can represent 2n numbers e.g. with 2 bits we can represent 22
=4 values/binary numbers i.e. 00, 01, 10, 11
Binary arithmetic
• Binary addition
o Similar to decimal addition
o Addition creates SUM bit and Carry bit
o In case of 3 or more 1s follow LCM/conversion to binary
o
Examples :
• Binary subtraction
o Similar to decimal subtraction
o If B is greater than A then 1 is borrowed from next position
Examples :
1. Subtract 00110 from 10100 (6 from 20)
• Binary multiplication
o Same as decimal numbers
o Follows following rules
- 0*0=0
- 0*1=0
- 1*0=0
- 1*1=1
Example multiply 1010 with 1011(10 with 11)
• Binary division
o Similar to decimal division
o Division occurs only if dividend is greater than or equal to divisor
o If dividend is less than divisor, then add 0 to quotient and bring down another bit
o Divide 510 by 5 for understanding
o Divide 173 by 14; 127101 by 121 for undertanding
o Divide 01001101 by 111
What will happen if you change the second last bit of dividend? Replace it with 1?
1.2 Decimal number system
• Most commonly used number system
• Base 10
• Consists of 10 digits from 0-9
CONVERSIONS
Possible conversions are
1. Decimal to binary
2. Decimal to octal
3. Decimal to hexadecimal
4. Binary to decimal
5. Binary to octal
6. Binary to hexadecimal
7. Octal to binary
8. Octal to decimal
9. Octal to hexadecimal
10. Hexadecimal to binary
11. Hexadecimal to octal
12. Hexadecimal to decimal
213
8 26 ------------- 5
8 3 -------------- 2
Method -2:
The 2nd method is to divide the numbers in the groups of 3, starting from the end (i.e
right) and then representing each group as an octal number. If the ending group has less than 3
numbers, add 0’s to the left of that number.
Example:
Convert 11010101 to octal.
Divide in the groups of 3 starting from the end.
11 010 101
Add zero to the right of 1st group to complete a group of 3 numbers.
011 010 101
Now in octal,
011 = 3
010 = 2
101 = 5
So, (11010101)2 is (325)8
3. Conversion of Binary to Hexa-decimal:
Conversion of binary to hexa-decimal is same as conversion to octal, except that now the
decimal number is divided by 16 i.e with the base of hexa-decimal.
Example:
Convert 11010101 to octal.
Step 1:
The 1st step is to convert the number to decimal:
1 × 27 + 1 × 26 + 0 × 25 + 1 × 24 + 0 × 23 + 1 × 22 + 0 × 21 + 1 × 20
128 + 64 + 0 + 16 + 0 + 4 + 0 + 1
213
Step 2:
The next step is the division by 16.
213
16 13 ------------- 5
4. Decimal to binary
Example:
Convert 213 to binary.
2 213
2 106 ------- 1
2 53 -------- 0
2 26 --------- 1
2 13 --------- 0
2 6 ----------- 1
2 3 ---------- 0
2 1 ---------- 1
So, (213)10 in binary is (11010101)2
Example:
Convert 213 to binary.
213
8 26 ------------- 5
8 3 -------------- 2
Method 1:
Example:
Convert (325)8 to binary.
2 3
1 ----- 1
2 2
1 ----- 0
2 5
2 2 ----- 1
1 ------
0
3 = 11 = 011
2 = 10 = 010
5 = 101
So, (325)8 = 011 010 101 = (11010101)2
Method 2:
Step 1: covert octal to decimal
Convert decimal to binary
Example:
Convert (325)8 to decimal
3 × 82 + 2 × 81 + 5 × 80
192 + 16 + 5
213
Hence the decimal of (325)8 is 213.
2 5
2 2 ---- 1
1 ---- 0
D=1101 5=101=0101
(D5)16 = (11010101)2
11. Conversion of hexa-decimal to Decimal:
To convert a number from hexa-decimal to decimal, we multiply each number by 16 and
then add the terms. The 16 carries a power relative to the place of number it is multiplied to.
Example:
Convert (D5)16 to decimal.
𝐷 × 161 + 5 × 160
208 + 5
213
12. Conversion of hexa-decimal to octal:
Separate the digits of the given hex number, if it contains more than 1 digit. Find the equivalent
binary number for each digit of hex number. Divide them in the groups of 3 and write the octal
for each group. If there are less than 3 numbers left for last group, just add a zero to the
beginning of number.
Example:
Convert (D5)16 to octal.
D=1101 5=0101
Groups of 3:
11 010 101
Add a zero to the beginning of 11.
011 010 101
Now assign octal number to each group:
011 = 3 010 = 2 101 = 5
Hence octal for (D5)16 is 325.