Ch01 Number Systems
Ch01 Number Systems
Decimal Numbers
The position of each digit in a weighted number system is
assigned a weight based on the base or radix of the system.
The radix of decimal numbers is ten, because only ten
symbols (0 through 9) are used to represent any number.
2
Decimal Number System
Base (also called radix) = 10
10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
Digit Position 2 1 0 -1 -2
Integer & fraction 5 1 2 7 4
Digit Weight
Position 100 10 1 0.1 0.01
Weight = (Base)
Magnitude
Sum of “Digit x Weight” 500 10 2 0.7 0.04
2 1 0 -1 -2
d2*B +d1*B +d0*B +d-1*B +d-2*B
3
Decimal Numbers
Decimal numbers can be expressed as the sum of the
products of each digit times the column weight for that
digit. Thus, the number 9243 can be expressed as
(9 x 103) + (2 x 102) + (4 x 101) + (3 x 100)
or
9 x 1,000 + 2 x 100 + 4 x 10 + 3 x 1
4
Binary Numbers
For digital systems, the binary number system is used.
Binary has a radix of two and uses the digits 0 and 1 to
represent quantities.
For whole binary numbers, the column weights are
powers of two that increase from right to left beginning
with 20 =1:
…25 24 23 22 21 20.
5
Binary Number System
Base = 2
2 digits { 0, 1 }, called binary digits or “bits”
Weights
Weight = 2Position 4 2 1 1/2 1/4
Magnitude
1 0 1 0 1
Sum of “Bit x Weight”
2 1 0 -1 -2
1*22 + 0*21 + 1*20 + 0*2-1 + 1*2-2
Formal Notation
Groups of bits 4 bits = Nibble =(5.25)10
8 bits = Byte (101.01)2
1011 11000101
6
Octal Number System
Octal Binary
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
7
Octal Number System
8
Hexadecimal Number System
Hex Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
9
Hexadecimal Number System
Formal Notation
(1E5.7A)16 =(485.4765625)10
10
The Power of 2
n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512
2 22=4 10 210=1024 Kilo
3 23=8 11 211=2048
4 24=16 12 212=4096
5 25=32 20 220=1M Mega
11
Decimal Binary
Binary Numbers Number Number
0 0000
A binary counting sequence for 1 0001
2 0010
numbers from zero to fifteen is 3 0011
shown. 4 0100
5 0101
Notice the pattern of zeros and ones in 6 0110
each column. 7 0111
8 1000
9 1001
Digital counters frequently have this 10 1010
same pattern of digits: 11 1011
12 1100
13 1101
14 1110
15 1111
12
Binary to Decimal Conversion
The decimal equivalent of a binary number can be determined by adding
the column values of all of the bits that are 1 and discarding all of the bits
that are 0.
Start by writing the column weights; then add the weights that correspond
to each 1 in the number.
13
Decimal (Integer) to Binary Conversion old method
Divide the number by the ‘Base’ (=2)
Take the remainder (either 0 or 1) as a coefficient
Example: (13)10
Quotient Remainder Coefficient
13 / 2 = 6 1 a0 = 1
6/ 2 = 3 0 a1 = 0
3/ 2 = 1 1 a2 = 1
1/ 2 = 0 1 a3 = 1
Answer: (13)10 = (a3 a2 a1 a0)2 = (1101)2
14
Decimal (Integer) to Binary Conversion (Subtraction)
You can convert a decimal whole number to binary by reversing the
procedure. Write the decimal weight of each column and place 1’s in the
columns that sum to the decimal number.
1. Write down column weights until the last weight is larger than or equal to
the one you want to convert.
49 2. Starting from the largest 6 25 24 23 22 2 1 20 .
-32 weight that is less than 2
17 or equal to what you 64 32 16 8 4 2 1.
-16 have, subtract 0 1 1 0 0 0 1.
1 repeatedly till it
-1 becomes zero
0 3. Fill in the existing ones by 1’s and the rest with 0’s
15
Decimal ( fraction) to Binary Conversions
16
Decimal ( fraction) to Binary Conversions
17
NEW:
95
Convert decimal 95 to binary. - 64
31
Solution (Old) : - 16
number Quotient reminder digit 15
- 8
95 ÷ 2 = 47 1 a0 = 1 7
47 ÷ 2 = 23 1 a1 = 1 - 4
3
23 ÷ 2 = 11 1 a2 = 1 - 2
11 ÷ 2 = 5 1 a3 = 1 1
- 1
5÷2= 2 1 a4 = 1 0
2÷2= 1 0 a5 = 0 Note:
1÷2= 0 1 a6 = 1 95 is 127 – 32
i.e. 7 1’s
answer is = a6 a5 a4 a3 a2 a1 a0 except for 32
= 1 0 1 1 1 1 1 = 95.
18
Decimal (Integer) to Octal Conversion
Example: (175)10
Quotient Remainder Coefficient
175 / 8 = 21 7 a0 = 7
21 / 8 = 2 5 a1 = 5
2 /8= 0 2 a2 = 2
Answer: (175)10 = (a2 a1 a0)8 = (257)8
Example: (195)10
Quotient Remainder Coefficient
195 / 8 = 24 3 a0 = 3
24 / 8 = 3 0 a1 = 0
3 /8= 0 3 a2 = 3
Answer: (195)10 = (a2 a1 a0)8 = (303)8
19
Decimal (fraction) to Octal Conversion
Example: (0.6325)10
Integer Fraction Coefficient
0.6325 * 8 = 5 . 060 a-1 = 5
0.06 * 8 = 0 . 4800 a-2 = 0
0.48 * 8 = 3 . 8400 a-3 = 3
Answer: (0.6325)10 = (0.a-1 a-2 a-3)8 = (0.503)8
Example: (0.3125)10
Integer Fraction Coefficient
0.3125 * 8 = 2 . 5 a-1 = 2
0.5 *8= 4 . 0 a-2 = 4
20
Binary to Octal Conversion Octal Binary
• 8 = 23 0 000
• Each group of 3 bits represents an 1 001
octal digit
2 010
Assume Zeros
Example:
3 011
( 1 0 1 1 0 . 0 1 )2 4 100
5 101
6 110
( 2 6 . 2 )8 7 111
21
Examples:
22
Examples:
23
Hex Binary
Binary − Hexadecimal Conversion 0 0000
1 0001
2 0010
16 = 24 3 0011
4 0100
Each group of 4 bits represents 5 0101
a hexadecimal digit 6 0110
Assume Zeros 7 0111
Example: 8 1000
9 1001
( 1 0 1 1 0 . 0 1 )2
A 1010
B 1011
C 1100
D 1101
(1 6 . 4 )16 E 1110
F 1111
24
Hex Binary
Binary − Hexadecimal Conversion 0 0000
1 0001
Example 2: 2 0010
3 0011
4 0100
Assume Zeros 5 0101
6 0110
( 1 0 1 1 0 1 1 0 . 0 1 )2 7 0111
8 1000
9 1001
A 1010
B 1011
( B 6 . 4 )16 C 1100
D 1101
E 1110
F 1111
25
Hex Binary
Hexadecimal - Binary Conversion 0 0000
1 0001
Example 3: 2 0010
3 0011
4 0100
( A E . 7 )16 5 0101
6 0110
7 0111
8 1000
9 1001
( 10 10 1110. 0111 ) A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
26
Hex Binary
Hexadecimal - Binary Conversion 0 0000
1 0001
Example 4: 2 0010
3 0011
4 0100
( D 3 . C )16 5 0101
6 0110
7 0111
8 1000
9 1001
( 11 01 0011. 1100 ) A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
27
Decimal, Binary, Octal and Hexadecimal
28
Decimal Binary BCD
BCD 0 0000 0000
1 0001 0001
Binary coded decimal (BCD) is
2 0010 0010
a weighted code that is commonly used in 3 0011 0011
digital systems when it is necessary to show 4 0100 0100
decimal numbers such as in clock displays. 5 0101 0101
6 0110 0110
7 0111 0111
The table illustrates the difference 8 1000 1000
between straight binary and BCD. 9 1001 1001
BCD represents each decimal digit 10 1010 --------------
with a 4-bit code. Notice that the 11 1011 --------------
codes 1010 through 1111 are not 12 1100 ------ -------
used in BCD. 13 1101 ------ -------
14 1110 ------ -------
15 1111 ------ -------
29
Decimal Binary Gray code
Gray code 0 0000 0000
1 0001 0001
2 0010 0011
Gray code is an unweighted 3 0011 0010
4 0100 0110
code that has a single bit change 5 0101 0111
between one code word and the 6 0110 0101
next in a sequence. 7 0111 0100
8 1000 1100
Gray code is used to avoid 9 1001 1101
problems in systems where an 10 1010 1111
error can occur if more than one 11 1011 1110
bit changes at a time. 12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
30
ASCII
ASCII is a code for alphanumeric characters and control characters.
In its original form, ASCII encoded 128 characters and symbols
using 7-bits.
The first 32 characters are control characters, that are based on
obsolete teletype requirements, so these characters are generally
assigned to other functions in modern usage.
31
Binary Addition
32
Binary Addition
Add the binary numbers 00111 and 10101 and show the
equivalent decimal addition.
0 1 1 1
0 0 1 1 1 7
1 0 1 0 1 21
1 1 1 0 0 = 28
Convert output binary to decimal:
32 16 8 4 2 1
0 1 1 1 0 0
---------------------------------
16 + 8 + 4 = 28
33
Binary Addition
Add the binary numbers 0011101 and 1010111 and show the
equivalent decimal addition.
0 1 1 1 1 1
0 0 1 1 1 0 1 29
1 0 1 0 1 1 1 87
1 1 1 0 1 0 0 = 116
Convert output binary to decimal:
64 32 16 8 4 2 1
1 1 1 0 1 0 0
-------------------------------------------
64 + 32 + 16 + 4 = 116
34
Binary Subtraction
0 1 1 0 1 1 0 = 54
35
Signed Binary Numbers
36
1’s Complement
The 1’s complement of a binary number is just the inverse of the digits.
To form the 1’s complement, change all 0’s to 1’s and all 1’s to 0’s.
0 0 1 1 0 1 0 1
37
2’s Complement
The 2’s complement of a binary number is found by adding 1 to the LSB of
the 1’s complement.
Recall that the 1’s complement of 11001010 is
00110101 (1’s complement)
+ 1
To form the 2’s complement, add 1:
00110110 (2’s complement)
1 1 0 0 1 0 1 0
0 0 1 1 0 1 0 1
Input bits 1
Carry
Adder
in (add 1)
Output bits (sum)
0 0 1 1 0 1 1 0
38
2’s Complement
The 2’s complement of a binary number is found by a short method.
00110110
The short method is:
Given number 11001010
Move from right till we reached first 1 leave
it and then inverse the remaining bits
00110110
39
2’s Complement
Find 2’s complement for the following:
(a) 10011101 01100011
(b) 10000010 01111110
(c) 11001111 00110001
(d) 00011100 11100100
(e) 01010101 10101011
(f) 10010011 01101101
40
Signed Binary Numbers
Negative numbers are written as the 2’s complement of the corresponding
positive number.
The negative number −58 is written as:
−58 = 11000110 (2’s complement form)
Sign bit
An easy way to read a signed number that uses this notation is to
assign the sign bit the negative of its column weight (−128 for an 8-
bit number). Then add the column weights for the 1’s.
41
Binary Subtraction using 2’s complement
42
Binary Subtraction using 2’s complement
Example:
Perform the following subtraction
00001000 - 00000011 = ?
8 - 3 = 5
Obtain the 2’s complement of the subtrahend and
ADD:
00001000 + 11111101
00001000
+ 11111101
1 00000101 = 5
Discard
43
Arithmetic Operations with Signed Numbers
Using the signed number notation with negative numbers in 2’s complement
form simplifies addition and subtraction of signed numbers.
Rules for addition: Add the two signed numbers. Discard any final
carries. The result is in signed form.
Examples:
44
Arithmetic Operations with Signed Numbers
Note that if the number of bits required for the answer is exceeded,
overflow will occur. This occurs only if both numbers have the same sign.
The overflow will be indicated by an incorrect sign bit.
45
Arithmetic Operations with Signed Numbers
Rules for subtraction: 2’s complement the subtrahend and add the
numbers. Discard any final carries. The result is in signed form.
46