Number Codes & Simple Binary Arithmetic

advertisement
Number Codes &
Simple Binary Arithmetic
The Denary No. System
Binary, Octal & Hexadecimal systems
Conversion from one no. system to another
Addition & Subtraction of nos. in any base
1
The Denary Number System
n the
commonest system used in arithmetic
n features
–
–
–
–
made up of ten digits: 0,1,2,3,4,5,6,7,8 & 9
its value depends on the digit & its position
no. value is the sum of digits’ values
e.g., 373 = 3 x 102 + 7 x 101 + 3 x 100
2
Binary, Octal & Hexadecimal Systems
n Base
– the no. of digits used in a number system
n Examples
–
–
–
–
denary:
base = 10,
binary:
base = 2,
octal:
base = 8,
hexadecimal: base = 16,
e.g.
e.g.
e.g.
e.g.
37310
101102
1578
A3F16
3
Binary System
n two
digits : 0 & 1
n positional values are 20, 21, 22, ... , etc.
n e.g.,
– 101102 = 1x24 + 0x23 + 1x22 + 1x21 + 0x20
= 16 + 4 + 2
= 2210
4
Octal System
n eight
digits : 0,1,2,3,4,5,6,7
n positional values are 80, 81, 82, ... , etc.
n e.g.,
– 1578 = 1 x 82 + 5 x 81 + 7 x 80
= 64 + 40 + 7
= 11110
5
Hexadecimal System
n sixteen
digits :
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E & F
n positional values are 160, 161, ... , etc.
n e.g.,
– A3F16 = A x 162 + 3 x 161 + F x 160
= 10 x 162 + 3 x 161 + 15 x 160
= 262316
6
Conversion into Denary
n
n
Algorithm
– Multiply each digit with its positional value and add up
all the products
e.g., convert the nos. 1001012 & BE16 into denary
– 1001012 = 1x25 + 0x24 + 0x23 + 1x22 + 0x21 + 1x20
= 3710
– BE16 = Bx161 + Ex160
= 11x16 + 14x1
= 19010
7
A quick method
n
n
Algorithm
– add up all the positional values of the 1s which occur in
the binary number
e.g., convert the nos. 101102 & 1001012 into denary
– 101102 = 24 + 22 + 21 = 16 + 4 + 2 = 2210
– 1001012 = 25 + 22 + 20 = 32 + 4 + 1 = 3710
8
Conversion fr. denary into others
n to
convert a denary no. into base b, where
b may stand for 2, 8 or 16
n Algorithm
– divide the denary no. by b
– keep dividing the resulting quotient by b until it
is smaller than b.
– combine the final quotient with the reminders
obtained in step 2 in the convert order
9
n
n
Convert 1988 into octal & hexadecimal nos.
Solution
8)1988
8)248...4
8)31...0
3...7
16)1988
16)124...4
7...C(i.e. 12)
– therefore, 198810 = 37048 = 7C416
10
Conversion fr. binary into octal & hex.
n convert
1010112 into octal
n Solution
n
1010112 = 1x25 + 0x24 + 1x23 + 0x22 + 1x21 + 1x20
= (1x22+ 0 x 21+ 1) x 23 + (0x22 + 1x21 + 1)
= (1012) x 23 + (0112)
= 538
1010112
5
3
11
n
Convert 1001101012 & 101102 into octal
1001101012 =
101102 =
n
Convert 1001101012 & 101102 into hexadecimal
1001101012 =
1101102 =
12
Conversion fr. octal & hex. into binary
n Convert
2748 into binary
– since 28 = 0102, 78 = 1112 and 48 = 1002
– 2748 = 0101111002 = 101111002
n Convert
7A16 into binary
– since 716 = 01112 and A16 = 10102
– 7A16 = 011110102 = 11110102
13
Addition & Subtraction
n refer
to the textbook
14
Download