binary

advertisement
Data Representation in
Computers
Number systems
The additive approach – Number earlier
consisted of symbols e.g. Roman number
system - I for 1, II for 2, III for 3 etc.

Positional numbering – Symbols represent
different values depending on the position
they occupy e.g. the Decimal system

Data Representation in Computers/Session 3 / 2 of 33
Decimal Number System
 365 = (3 * 100) + (6*10) + (5*1)
 The value of each digit in the
number system is determined by:
The digit itself
The position of the digit in the
number
The base/radix of the system
(6*10)
Base
Position number
Data Representation in Computers/Session 3 / 3 of 33
Binary Number System
 The binary number system has a base of two and
symbols used are 0 and 1.
 In this number system, as we move to the left, the
value of the digit will be two times greater than its
predecessor because the base is two.
 Thus the value of the places are :
128  64  32  16  8  4  2  1
0001 1110 0101 0111
Most Significant bit
Binary Number
Least Significant bit
Data Representation in Computers/Session 3 / 4 of 33
Octal number systems
 Uses a base of 8
Binary
000
 Values increase
001
from right to left 1,
010
8, 64, 512, 4096 ...
 Example: 1204
= (1 * 512) + (2 * 64) +
(0 * 8) + (4 * 1)
= 512 + 128 + 0 + 4
= 644
011
100
101
110
111
Octal
0
1
2
3
4
5
6
7
Data Representation in Computers/Session 3 / 5 of 33
Hexadecimal Number Systems
 Uses a base of 16
 The 16 symbols required for the
hexadecimal number system
obtainedby using the alphabets A,
B, C, D, E and F
 Example: A0119
= (10 * 65,536)+(0 * 4,096)+(1 *
256)+ ( 1 * 16) + ( 9 * 1)
= 6,55,360 + 0 + 256 + 16 + 9
= 6, 55, 641
Hexadecimal
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
Decimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Data Representation in Computers/Session 3 / 6 of 33
Octal  Binary Conversion
 Binary to octal : group 3 bits from right to left
 Otal to binary : each digit is represented by 3 bits
Binary
Octal
000
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
Data Representation in Computers/Session 3 / 7 of 33
Binary  Decimal Conversion
 Binary to decimal:
…128<64 <32 <16 <8 <4 <2 <1
Or
anan-1….a2a1a0 =
an*2n + an-1*2n-1 +….+a2*22+a1*21+a0*20
 The decimal equivalent of 110100 is
= (1 * 32 ) + (1 * 16) + (0 * 8) +
( 1 * 4) + ( 0 * 2) + (0 * 1)
= 32 + 16 + 0 + 4 + 0 + 0
= 52
Data Representation in Computers/Session 3 / 8 of 33
Binary  Decimal Conversion

Decimal to Binary:

Divide the decimal number by 2

Note the remainder in one column and divide
the quotient again with 2

Keep repeating this process until quotient is
reduced to a zero

Reading remainders in the reverse order gives
the binary equivalent
Data Representation in Computers/Session 3 / 9 of 33
Example
E.g. Converting the decimal number 52 to its
binary equivalent.
52 |_2_
0 26 |_2_
0 13 |_2_
1 6 |_2_
0 3 |_2_
1 1 |_2_
1 0
Thus the binary equivalent of the decimal
number 52 is 11 01 00
Data Representation in Computers/Session 3 / 10 of 33
Binary Hexadecimal conversion
 Hexa to binary : Each hexadecimal digit is
represented by 4 bits
Example: 1A412C is represented
0001 1010 0100 0001 0010 1100
Delete digits 0 on the left
 110100100000100101100
 Binary to hexa:
 Group 4 digits from right to left
 Convert groups to 16 base
Example: 10101011000010
0010 1010 1100 0010
2
A
C
2
Data Representation in Computers/Session 3 / 11 of 33
Data Representation
 Digital computers use binary code to represent
characters.
 Binary code is made up of binary digits or bits.
 A string of "0s" and "1s" is used to represent
characters.
 Byte is a sequence of 8 bits.
 Most computers have words that consist of
8 or 16 bits.
 In large computers the number of bits per
word could be 16 or 32 bits.
Data Representation in Computers/Session 3 / 12 of 33
Binary Arithmetic Addition
The following rules of binary addition
are to be remembered:
0+0=0
0+1=1=1+0
1 + 1 = 0 carry 1 to the next column to
the left
1 + 1 + 1 = 1 carry 1 to the next column
e.g. Carry 1 1 1 1
1 10 11
+ 1 11
10 00 10
Data Representation in Computers/Session 3 / 13 of 33
Complementary Subtraction

Three steps to perform subtraction :

Find the complement of the number you are subtracting
 To the complement of the number add the number we are
subtracting from
 If there is a carry of 1 add the carry to the result of the
addition
Else
re-complement the sum and attach a negative sign
e.g.
Number
10 00 11 01
00 10 10 10
Complement
01 11 00 10
11 01 01 01
Data Representation in Computers/Session 3 / 14 of 33
Complementary Subtraction
(Contd.)
Example of subtraction :
e.g. 1010101 - 1001100
Step 1. Find the complement of 1001100  0110011
Step 2. Do the Add operation
carry 11 1 011 1
1 01 01 01
+ 0 11 00 11
0 00 10 00
Since there is a carry of 1, Add the carry
0 00 10 00
+
1
0 00 10 01
Data Representation in Computers/Session 3 / 15 of 33
Complementary Subtraction
(Contd.)
e.g.2 101100 - 11100101
Step 1.
Complement of 11100101 is 00011010
Step 2.
Carry
01 11
00 10 11 00
+00 01 10 10
01 00 01 10
Step 3. Since there is no carry we
re-complement the result and add a
negative sign
Thus the answer is -10111001
Data Representation in Computers/Session 3 / 16 of 33
Multiplication
Rules for Multiplication:
0x0=0
0x1=0
1x0=0
1x1=1
E.g.. 10101 * 11001
10101
x11001
------10101
00000
00000
10101
10101
----------1000001101
Data Representation in Computers/Session 3 / 17 of 33
Division
1. Start from the left of the dividend
2. Perform subtraction i.e. divisor should be
subtracted from the dividend
a) if subtraction is possible put 1 in the
quotient and subtract the divisor
from digits of the dividend
else
put 0 in the quotient
b) bring down the next digit to the
right of the remainder
3. Do step 2 till no more digits remain in
the dividend
Data Representation in Computers/Session 3 / 18 of 33
Example
The complete table for binary division is:
0/1 = 0
1/1 = 1
E.g
100001 / 110
Then
0101 (Quotient)
________
(Divisor) 110 | 1000 01 (Dividend)
- 110
10 0
10 01
1 10
11
Quotient
101
(Remainder)
Data Representation in Computers/Session 3 / 19 of 33
Download