Lecture 2 - Number Systems
Lecture 2 - Number Systems
SYSTEM
Chapter 1 NUMBER SYSTEM
TABLE OF CONTENTS
Introduction ……………………………………………………………………………………. 2
Kinds of Number System ……………………………………………………………………………… 3
Decimal Number System …………………………………………………………………… 3
Binary Number System ……………………………………………………………………… 3
Octal Number System ………………………………………………………………………... 4
Hexadecimal Number System …………………………………………………………….. 4
Mathematical Operation ………………………………………………………………………………. 6
Addition of Binary Numbers ……………………………………………………………… 6
Multiplication of Binary Numbers ……………………………………………………… 7
Division of Binary Numbers ……………………………………………………................ 8
Addition of Octal and Hexadecimal Numbers ……………………………………… 10
Multiplication of Octal and Hexadecimal Numbers ……………………………… 11
Division of Octal and Hexadecimal Numbers ………………………………………. 13
Addition and Multiplication Table for Binary,
Octal and Hexadecimal Number System ………………………................. 16
Complement ………………………………………………………………………………………………... 18
Radix complement (r's) complement …………………………………………………. 18
Diminished Radix Complement (r -1)’s complement …………………………... 19
Subtraction using r's complement Method ……………………………..………….. 19
Subtraction using (r - 1)'s complement Method ………………………………..... 20
Conversion …………………………………………………………………………………………………. 22
Binary, Octal, Hexadecimal to Decimal Conversion ………………………….…. 22
Decimal to Binary, Octal, Hexadecimal Conversion …………………………..… 23
Binary to Octal and Hexadecimal Conversion ………………………….…………. 24
Octal and Hexadecimal to Binary Conversion ……………………………….……. 24
Codes ……………………………………………………………………………………….…………..…….. 25
Binary Codes ………………………………………………………………….………………… 25
Other 4-Bit Code, Excess-3 Code ……………………………………............. 25
Five-bit Code, More than 5 – bit code ……………………………………… 26
Alphanumeric Code ………………………………………………………………………..… 27
ASCII ………………………………………………………………………………….….. 27
EBCIDIC ………………………………………………………………………………… 30
Parity Code …………………………………………………………………………………..….. 32
1
Chapter 1 NUMBER SYSTEM
NTRODUCTION
Since childhood, we have learned to do our computations using the numbers
0 - 9, the digits of the decimal number system. In fact, we are so accustomed to
working with decimal numbers
that we hardly think about their use. We pay monthly bills, and even solve algebra
homework with the aid of the decimal number system.
But decimal number system is not the only type of number system, these also
includes the binary, octal, and hexadecimal number system.
While the binary number system is very important because of its connection
with computers, it is not the only other number system of importance. The octal number
system is a base-8 number system and uses the digits 0 - 7 to represent numbers. The
hexadecimal number system is a base-16 number system and uses the digits 0 - 9 along
with the letters A - F to represent numbers.
2
Chapter 1 NUMBER SYSTEM
Decimal notation often refers to a base-10 positional notation such as the Hindu-
Arabic numeral system; however, it can also be used more generally to refer to non-
positional systems such as Roman or Chinese numerals which are also based on powers of
ten.
This kind of number system uses the values from 0-9 and also these are the regular
numbers that we used.
12 1 1 0 0
13 1 1 0 1
14 1 1 1 0
15 1 1 1 1
16 1 0 0 0 0
17 1 0 0 0 1
18 1 0 0 1 0
19 1 0 0 1 1
Value 24 23 22 21 20
Powers of 2
Table 1 Counting in binary and decimal
Counting in binary is illustrated in Fig. 1. The binary number is shown on the right
with its decimal equivalent. Notice that every bit place has its corresponding value. The
least significant (LSB) is the 1s place. In other words, if a 1 appears in the right column, a 1
is added to the binary count. The second place is the 2s place, means that whenever there is
1 in the second 2 is added to the binary count. Hence, each place value can be simplified as
2n, where n is the place of the digit starting with 0.
The octal numeral system is the base-8 number system, meaning eight symbols are
used to represent all the quantities. It uses the values from 0 to 7.
Hexadecimal Numbers
Hexadecimal numbers system or base-16 number system has a radix of 16. It uses
values from 0-15 where values from 10-15 are represented by A-F. The usefulness in
converting directly from a 4-bit binary number is one of its advantages.
4
Chapter 1 NUMBER SYSTEM
Each hexadecimal digit represents four binary digits (bits) which also a nibble,
which half of an octet or a byte (8 binary digits or bits). The primary use of a hexadecimal
notation is a human-friendly representation of binary-coded values in computing and
digital electronics. For example, byte values can range from 0 to 255 (decimal), but may be
simply and more conveniently represented as two hexadecimal digits in the range 00 to FF.
Hexadecimal is also commonly used to represent computer memory addresses.
Notice that the hexadecimal equivalent of the decimal 16 is 10, simply because it
uses the place value idea. The first hexadecimal digit has 160 values, the second has 161,
and the third has 162, and so on. The 1 (in 1016) stands for 16 units, while the 0 stands for
zero units.
5
Chapter 1 NUMBER SYSTEM
ATHEMATICAL OPERATION
Addition of Binary Numbers
Addition of binary numbers is the same and simpler compared to
adding decimal numbers
PROCEDURE:
Example:
100110101 + 110011100
1) Align LSBs
1 0 0 1 1 0 1 0 1
+ 1 1 0 0 1 1 1 0 0
1 0 0 1 1 0 1 0 1 a) 1 + 0 = 1
+ 1 1 0 0 1 1 1 0 0 b) 0 + 0 = 0
0 1
6
Chapter 1 NUMBER SYSTEM
1 1 1 1
1 0 0 1 1 0 1 0 1
+ 1 1 0 0 1 1 1 0 0
1 0 1 1 0 1 0 0 0 1 Result
PROCEDURE:
Example:
10101 x 11100
1) Align LSBs
1 0 1 0 1 Multiplicand
x 1 1 1 0 0 Multiplier
1 0 1 0 1
x 1 1 1 0 0 10101x0=00000
1 0 1 0 1
x 1 1 1 0 0
0 0 0 0 0
7
Chapter 1 NUMBER SYSTEM
1 0 1 0 1
x 1 1 1 0 0
0 0 0 0 0
0 0 0 0 0
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
5) Add
1 0 1 0 1
x 1 1 1 0 0
0 0 0 0 0
0 0 0 0 0
1 0 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 0 1 0 0 1 1 0 0
PROCEDURE:
1) Count the number of bits of the divisor (Let n be the number of bits of divisor).
2) If the first n bits of the dividend are equal or greater than the n bits of the
divisor, write 1 at the nth bit, otherwise, write 0 then bring down the next bit.
3) Multiply the bit quotient to the divisor and then subtract it to the n or (n + 1) bits
that are used in step (2).
4) After subtracting, bring down the next bits to make n bits again then repeat steps
(2) and (3).
8
Chapter 1 NUMBER SYSTEM
Example:
1011001 ÷ 101
1) Count the bits of the divisor.
n=3
2) Compare
1
101 1 0 1 1 0 0 1 101 = 101, Quotient = 1
1
101 1 0 1 1 0 0 1
- 1 0 1
0 0 0
4) Bring down
1 0 0 0 1 Quotient
101 1 0 1 1 0 0 1
- 1 0 1
1 0 0 101 > 100
- 0 0 0
1 0 0 1 101 < 1001
- 1 0 1
1 0 0 Remainder
All operations were used in binary system. Other number systems like
octal and hexadecimal number system have the same procedure like the
binary number system but with an additional step if dealing with carry.
9
Chapter 1 NUMBER SYSTEM
Example:
17458 + 23648
1 7 4 5
+ 2 3 6 4
9 if the sum is greater than the base number system,
subtract the base number to the sum then add 1 to
the next position.
1
1 7 4 5
+ 2 3 6 4
9
- 8
1
1 1
1 7 4 5
+ 2 3 6 4 Repeat procedure
1 1 1
- 8
3
1 1 1
1 7 4 5
+ 2 3 6 4
4 3 3 1 Result
10
Chapter 1 NUMBER SYSTEM
Example:
45AC16 + 12E316
4 5 A C
+ 1 2 E 3
15 15 in Hexadecimal character is “F”
1
4 5 A C
+ 1 2 E 3
8 F
1
4 5 A C
+ 1 2 E 3
5 8 8 F Result
Example:
748 x 258
7 4 carry
x 2 5
20 20 – 2(8) = 4, carry 2
2
7 4
x 2 5
37 4 37 – 4(8) = 5, carry 4
11
Chapter 1 NUMBER SYSTEM
7 4
x 2 5
4 5 4
8 8 – 1(8) = 0, carry 1
7 4
x 2 5
4 5 4
14 8 14 – 1(8) = 6, carry 1
7 4
x 2 5
4 5 4
1 6 8 Add
7 4
x 2 5
4 5 4
1 6 8
13 4 13 – 1(8) = 5, carry 1
7 4
x 1 2 5
4 5 4
1 6 8
11 5 4 11 – 1(8) = 3, carry 1
7 4
x 1 2 5
1 4 5 4
1 6 8
2 3 5 4 Result
12
Chapter 1 NUMBER SYSTEM
Example:
42718 ÷ 168
2
16 4 2 7 1 28 x 168 = 348
- 3 4 428 – 348 = 68
6 7
2
16 4 2 7 1
- 3 4
6 7 678 = 5510, 168 = 1410
5510 ÷ 1410 = 310 , disregard
remainder
310 = 38
2 3
16 4 2 7 1
- 3 4
6 7 38 x 168 = 528
-5 2 678 – 528 = 158
1 5 1
13
Chapter 1 NUMBER SYSTEM
2 3
16 4 2 7 1
- 3 4
6 7
-5 2
1 5 1 1518 = 10510, 168 = 1410
10510 ÷ 1410 = 710 , disregard
remainder
710 = 78
2 3 7 Quotient
16 4 2 7 1
- 3 4
6 7
-5 2
1 5 1 78 x 168 = 1428
-1 4 2
7 Remainder
Example:
FFFF16 ÷ 2116
7
21 F F F F 716 x 2116 = E716
- E 7 FF16 – E716 = 1816
1 8 F
7
21 F F F F
- E 7
1 8 F 18F16 = 39910, 2116 = 3310
18F10 ÷ 3310 = 1210 , disregard
remainder
1210 = C16
14
Chapter 1 NUMBER SYSTEM
7 C
21 F F F F
- E 7
1 8 F C16 x 2116 = 18C16
-1 8 C 18F16 – 18C16 = 316
3 F
7 C
21 F F F F
- E 7
1 8 F
-1 8 C
3 F 3F16 = 6310, 218 = 3310
6310 ÷ 3310 = 110 , disregard
remainder
110 = 116
7 C 1 Quotient
21 F F F F
- E 7
1 8 F
-1 8 C
3 F 116 x 2116 = 2116
-2 1 3F16 – 2116 = 1E16
1 E Remainder
15
Chapter 1 NUMBER SYSTEM
+ 0 1 x 0 1
0 0 1
0 0 0
1 1 10
1 0 1
+ 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7 10
2 2 3 4 5 6 7 10 11
3 3 4 5 6 7 10 11 12
4 4 5 6 7 10 11 12 13
5 5 6 7 10 11 12 13 14
6 6 7 10 11 12 13 14 15
7 7 10 11 12 13 14 15 16
x 0 1 2 3 4 5 6 7
0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7
2 0 2 4 6 10 12 14 16
3 0 3 6 11 14 17 22 25
4 0 4 10 14 20 24 30 34
5 0 5 12 17 24 31 36 43
6 0 6 14 22 30 36 44 52
7 0 7 16 25 34 43 52 61
16
Chapter 1 NUMBER SYSTEM
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
0 0 1 2 3 4 5 6 7 8 9 A B C D E F
1 1 2 3 4 5 6 7 8 9 A B C D E F 10
2 2 3 4 5 6 7 8 9 A B C D E F 10 11
3 3 4 5 6 7 8 9 A B C D E F 10 11 12
4 4 5 6 7 8 9 A B C D E F 10 11 12 13
5 5 6 7 8 9 A B C D E F 10 11 12 13 14
6 6 7 8 9 A B C D E F 10 11 12 13 14 15
7 7 8 9 A B C D E F 10 11 12 13 14 15 16
8 8 9 A B C D E F 10 11 12 13 14 15 16 17
9 9 A B C D E F 10 11 12 13 14 15 16 17 18
A A B C D E F 10 11 12 13 14 15 16 17 18 19
B B C D E F 10 11 12 13 14 15 16 17 18 19 1A
C C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B
D D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C
E E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D
F F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E
17
Chapter 1 NUMBER SYSTEM
OMPLEMENT
Complements are used for simplifying the operation of subtraction in
number system and also for logical manipulation. There are two types of
complements for binary as well as decimal number system which are radix
complement and diminished radix complement.
The r’s complement is known as 2's complement and (r-1)’s
complement is 1's complement for a Binary System. For Decimal Number System, radix
complement is known as 10's complement and Diminished Radix Complement (r-1)’s
complement is 9's Complement.
If we are given any number N having digits n in base r system, then r's complement
can be defined as rn-N for N not equal to zero and for N=0.
Example:
10’s complement of 45678
rn-N = 105-45678 = 54322
10’s complement of 0.22393
rn-N = 100-0.22393 = 0.77607
2’s complement of (10100)
rn-N = 25-(10100) = 100000-10100 = 1100
For the first given example, the 10's complement of 45678 is obtained by using the
formula rn-N. The small n indicates the number of significant digits in the given N and r is
the base number which is 10.
18
Chapter 1 NUMBER SYSTEM
If we are given any number N having digits n in base r system, then (r-1)’s
complement can be defined as rn-r-m-N.
Example:
9’s complement of 45678
rn-r-m-N = 105 – 100 – 45678 = 54321
9’s complement of 0.22393
rn-r-m-N = 100 – 10-5 – 0.22393 = 0.77607
1’s complement of (10100)
rn-r-m-N = 25 – 20 – (10100)
= 100000 – 000001 – 010100
= 1011
For the first given example, the 9’s complement of 45678 is obtained using the
formula of the (r-1)’s complement which is rn-r-m-N. The m indicates the fraction part of
the given N and the small letter n is the number of significant digits. Applying the formula
will give us the answer that must be the difference of 10’s complement minus 1.
19
Chapter 1 NUMBER SYSTEM
20
Chapter 1 NUMBER SYSTEM
2. A carry in the sum of S and M has a meaning. If a carry occurs, bring it down add
it to get the true answer and if there is no carry, take the (r-1)’s complement of
the result and place a negative sign in front for the answer.
21
Chapter 1 NUMBER SYSTEM
ONVERSION
Number systems can be converted to another number system
with different radix as long as their numerical/decimal values remains the
same. For example, 208 and 100002 are equivalent since they have the same
numerical/decimal value of 16.
22
Chapter 1 NUMBER SYSTEM
If the decimal has a radix point and contains a fractional or decimal part, we use
successive multiplication by r of the decimal part and carried out the integer part and
placed it after the radix point.
23
Chapter 1 NUMBER SYSTEM
24
Chapter 1 NUMBER SYSTEM
ODES
Code is a set of symbols with specific meaning used for representing
something. The most common and frequently used codes in digital
electronics are the Binary Codes, Alphanumeric Codes, and Parity Codes.
BINARY CODES
The baseline of all programming language. It is considered as the back end of all
computer functioning. Objects are represented using the binary number system, which has
only two values, either 1 or 0.
DECIMAL BINARY
Base - 10 Base - 2
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
25
Chapter 1 NUMBER SYSTEM
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
26
Chapter 1 NUMBER SYSTEM
5 – BIT CODE
ALPHANUMERIC CODES
A code where both numbers and letters are utilized to represent the decimal digits 0
– 9. There are several types of alphanumeric code, two of them are:
A. ASCII
27
Chapter 1 NUMBER SYSTEM
Stands for “American Standard Code for Information Interchange”. It is a seven – bit
code, thus allowing a total of 128 different combinations. An additional bit is usually
added and it is always set to 0 or 1 or used as a parity bit
CHAR BINARY OCTAL DECIMAL HEXADECIMAL DESCRIPTION
00100000 040 32 20 space
! 00100001 041 33 21 exclamation mark
" 00100010 042 34 22 double quotes
# 00100011 043 35 23 number sign
$ 00100100 044 36 24 dollar sign
% 00100101 045 37 25 percent sign
& 00100110 046 38 26 ampersand
' 00100111 047 39 27 single quote
( 00101000 050 40 28 opening parenthesis
) 00101001 051 41 29 closing parenthesis
* 00101010 052 42 2A asterisk
+ 00101011 053 43 2B plus sign
, 00101100 054 44 2C comma
- 00101101 055 45 2D minus sign, hyphen
. 00101110 056 46 2E period, dot
/ 00101111 057 47 2F division sign, slash
0 00110000 060 48 30 zero
1 00110001 061 49 31 one
2 00110010 062 50 32 two
3 00110011 063 51 33 three
4 00110100 064 52 34 four
5 00110101 065 53 35 five
6 00110110 066 54 36 six
7 00110111 067 55 37 seven
8 00111000 070 56 38 eight
9 00111001 071 57 39 nine
: 00111010 072 58 3A colon
; 00111011 073 59 3B semicolon
< 00111100 074 60 3C less than sign
= 00111101 075 61 3D equal sign
> 00111110 076 62 3E greater than sign
? 00111111 077 63 3F question mark
@ 01000000 100 64 40 at symbol
A 01000001 101 65 41 capital letter a
B 01000010 102 66 42 capital letter b
C 01000011 103 67 43 capital letter c
D 01000100 104 68 44 capital letter d
28
Chapter 1 NUMBER SYSTEM
29
Chapter 1 NUMBER SYSTEM
B. EBCDIC
Stands for “Extended Binary Coded Decimal Interchange Code”. It is a type of
alphanumeric code similar to ASCII but less popular. An 8 – bit code without a parity
and uses binary coded decimal as the basis of binary assignment. A ninth bit may or
may not be added for parity.
Dec Hex Char Dec Hex Char Dec Hex Char Dec Hex Char
0 00 NUL 64 40 space 128 80 192 C0 {
1 01 SOH 65 41 129 81 a 193 C1 A
2 02 STX 66 42 130 82 b 194 C2 B
3 03 ETX 67 43 131 83 c 195 C3 C
4 04 68 44 132 84 d 196 C4 D
5 05 HT 69 45 133 85 e 197 C5 E
6 06 70 46 134 86 f 198 C6 F
7 07 DEL 71 47 135 87 g 199 C7 G
8 08 72 48 136 88 h 200 C8 H
9 09 73 49 137 89 i 201 C9 I
10 0A 74 4A [ 138 8A 202 CA
11 0B VT 75 4B . 139 8B 203 CB
12 0C FF 76 4C < 140 8C 204 CC
13 0D CR 77 4D ( 141 8D 205 CD
14 0E SO 78 4E + 142 8E 206 CE
30
Chapter 1 NUMBER SYSTEM
15 0F SI 79 4F |! 143 8F 207 CF
16 10 DLE 80 50 & 144 90 208 D0 }
17 11 81 51 145 91 j 209 D1 J
18 12 82 52 146 92 k 210 D2 K
19 13 83 53 147 93 l 211 D3 L
20 14 84 54 148 94 m 212 D4 M
21 15 85 55 149 95 n 213 D5 N
22 16 BS 86 56 150 96 o 214 D6 O
23 17 87 57 151 97 p 215 D7 P
24 18 CAN 88 58 152 98 q 216 D8 Q
25 19 EM 89 59 153 99 r 217 D9 R
26 1A 90 5A !] 154 9A 218 DA
27 1B 91 5B $ 155 9B 219 DB
28 1C IFS 92 5C * 156 9C 220 DC
29 1D IGS 93 5D ) 157 9D 221 DD
30 1E IRS 94 5E ; 158 9E 222 DE
31 1F IUS 95 5F ^ 159 9F 223 DF
32 20 96 60 - 160 A0 224 E0 \
33 21 97 61 / 161 A1 ~ 225 E1
34 22 98 62 162 A2 s 226 E2 S
35 23 99 63 163 A3 t 227 E3 T
36 24 100 64 164 A4 u 228 E4 U
37 25 LF 101 65 165 A5 v 229 E5 V
38 26 ETB 102 66 166 A6 w 230 E6 W
39 27 ESC 103 67 167 A7 x 231 E7 X
40 28 104 68 168 A8 y 232 E8 Y
41 29 105 69 169 A9 z 233 E9 Z
42 2A 106 6A | 170 AA 234 EA
43 2B 107 6B , 171 AB 235 EB
44 2C 108 6C % 172 AC 236 EC
45 2D ENQ 109 6D _ 173 AD 237 ED
46 2E ACK 110 6E > 174 AE 238 EE
47 2F BEL 111 6F ? 175 AF 239 EF
48 30 112 70 176 B0 240 F0 0
49 31 113 71 177 B1 241 F1 1
50 32 SYN 114 72 178 B2 242 F2 2
51 33 115 73 179 B3 243 F3 3
52 34 116 74 180 B4 244 F4 4
53 35 117 75 181 B5 245 F5 5
54 36 118 76 182 B6 246 F6 6
55 37 EOT 119 77 183 B7 247 F7 7
31
Chapter 1 NUMBER SYSTEM
PARITY CODE
A bit added to transmitted binary signal either byte or word to detect errors in the
transmission. The two types of parity code are even parity and odd parity. In even parity,
the total number of 1’s will become even in number while in odd parity, the total number of
1’s will become odd in number.
32