0% found this document useful (0 votes)
21 views46 pages

Ch01 Number Systems

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views46 pages

Ch01 Number Systems

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

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.

The column weights of decimal integer numbers are powers


of ten that increase from right to left beginning with 100 =1:

…105 104 103 102 101 100.

For fractional part of decimal numbers, the column weights


are negative powers of ten that decrease from left to right:

102 101 100. 10-1 10-2 10-3 10-4 …

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

 Formal Notation (512.74)10

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

Express the number 480.52 as the sum of


values of each digit.

480.52 = (4 x 102) + (8 x 101) + (0 x 100) + (5 x 10-1) +(2 x 10-2)

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.

For fractional part of binary numbers, the column


weights are negative powers of two that decrease from
left to right:
22 21 20. 2-1 2-2 2-3 2-4 …

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

 Base =8 example (512.74)8 =( )10


 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
 Weights 64 8 1 1/8 1/64
Position
 Weight = (Base) 5 1 2 7 4
2 1 0 -1 -2
 Magnitude
5*82+1*81+2*80+7*8-1+4 *8-2
 Sum of “Digit x Weight”
=(330.9375)10
 Formal Notation
(512.74)8 =(330.9375)10

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

example (1E5.7A)16 =( )10


 Base = 16
 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }
256 16 1 1/16 1/256
 Weights 1 E 5
Position
7 A
 Weight = (Base) 2 1 0 -1 -2
 Magnitude 1 *162+14 *161+5 *160+7 *16-1+10 *16-2

 Sum of “Digit x Weight” =(485.4765625)10

 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

6 26=64 30 230=1G Giga

7 27=128 40 240=1T Tera

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.

Convert the binary number 100101.01 to decimal.

Start by writing the column weights; then add the weights that correspond
to each 1 in the number.

25 24 23 22 21 20. 2-1 2-2


32 16 8 4 2 1 . ½ ¼
1 0 0 1 0 1. 0 1
32 +4 +1 +¼ = 37¼

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

 Take the quotient and repeat the division till quotient


becomes zero

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.

Convert the decimal number 49 to binary.

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

 Multiply the number by the ‘Base’ (=2)


 Take the integer (either 0 or 1) as the current digit
 Take the resultant fraction and repeat the Above
process.
Example: (0.625)10
Integer Fraction Coefficient
0.625 * 2 = 1 . 25 a-1 = 1
0.25 * 2 = 0 . 5 a-2 = 0
0.5 * 2 = 1 . 0 a-3 = 1
Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2

16
Decimal ( fraction) to Binary Conversions

You can convert a decimal fraction to binary by repeatedly multiplying the


fractional results of successive multiplications by 2. The carries form the
binary number.

Convert the decimal fraction 0.188 to binary by repeatedly multiplying the


fractional results by 2.

0.188 x 2 = 0.376 a-1 = 0


0.376 x 2 = 0.752 a-2 = 0
0.752 x 2 = 1.504 a-3 = 1
0.504 x 2 = 1.008 a-4 = 1
0.008 x 2 = 0.016 a-5 = 0
Answer = .00110 (for five digits)

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

Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8

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

Works both ways (Binary to Octal & Octal to Binary)

21
Examples:

Convert the following octal numbers to binary:

(a) 138 (b) 258 ( c ) 1408 (d) 75268


solution:

(a) (13)8 ( 001 011)2


(b) (25)8 ( 010 101)2
(c) (140)8 (001 100 000)2
(d) (7526)8 (111 101 010 110)2

22
Examples:

Convert the following binary numbers to octal:


(a) 110101 (b) 100010 ( c ) 1101100
solution:

(a) (110 101) ( 65)8

(b) ( 100 010) ( 42)8

(c) (1 101 100) ( 154)8

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

Works both ways (Binary to Hex & Hex to Binary)

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

Works both ways (Binary to Hex & Hex to Binary)

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

Works both ways (Binary to Hex & Hex to Binary)

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

Works both ways (Binary to Hex & Hex to Binary)

27
Decimal, Binary, Octal and Hexadecimal

Decimal Binary Octal Hex


00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

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.

In 1981, IBM introduced extended ASCII, which is an 8-bit code and


increased the character set to 256.

Other extended sets (such as Unicode) have been introduced to


handle characters in languages other than English.

31
Binary Addition

Rules of Binary Addition with carry :

cin 0 cin 0 cin 0 cin 0


+ A 0 + A 1 + A 0 + A 1
+ B 0 + B 0 + B 1 + B 1
00 01 01 10
sum 0 cout = 0 sum 1 cout = 0 sum 1 cout = 0 sum 0 cout = 1

cin 1 cin 1 cin 1 cin 1


+ A 0 + A 1 + A 0 + A 1
+ B 0 + B 0 + B 1 + B 1
01 10 10 11
sum 1 cout = 0 sum 0 cout = 1 sum 0 cout = 1 sum 1 cout = 1

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

• Borrow a “Base” when needed


1 2 = (10)2
0 2 2 0 0 2
1 0 0 1 1 0 1 = 77
− 1 0 1 1 1 = 23

0 1 1 0 1 1 0 = 54

35
Signed Binary Numbers

There are several ways to represent signed binary numbers. In all


cases, the MSB in a signed number is the sign bit, that tells you if
the number is positive or negative.

Computers use 2’s complement for signed numbers. Positive


numbers are stored in true form (with a 0 for the sign bit) and
negative numbers are stored in complement form (with a 1 for the
sign bit).

For example, the positive number 58 is written using 8-bits as


00111010 (true form).

Sign bit Magnitude bits

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.

For example, the 1’s complement of 11001010 is


00110101
In digital circuits, the 1’s complement is formed by using inverters:
1 1 0 0 1 0 1 0

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.

From last example 2’s complement of 11001010 is

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.

Noting that the sign bit = −128, show that


11000110 = −58

Column weights: −128 64 32 16 8 4 2 1.


1 1 0 0 0 1 1 0
−128 +64 + 4 +2 = −58

41
Binary Subtraction using 2’s complement

Subtraction is a special case of addition.

The subtraction sign is replaced by the negation of the


number and converted to an add:
A – B = A + (-B) i.e. A + 2B

Discard any final carry

Both numbers must have same number of bits.

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:

00011110=+30 00001110 = +14 11111111 = −1


00001111=+15 11101111 = −17 11111000 = −8
00101101= +45 11111101 = −3 1 11110111 = −9
Discard carry

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.

Two examples are:

01000000 = +128 10000001 = −127


01000001 = +129 10000001 = −127
10000001 = −126 Discard carry 100000010 = +2

Wrong! The answer is incorrect and the sign


bit has changed.

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.

Repeat the examples done previously, but subtract:

00011110 (+30) 00001110 (+14) 11111111 (−1)


− 00001111 –(+15) − 11101111 –(−17) − 11111000 –(−8)

2’s complement subtrahend and add:


00011110 = +30 00001110 = +14 11111111 = −1
11110001 = −15 00010001 = +17 00001000 = +8
1 00001111= +15 00011111 = +31 1 00000111= +7
Discard carry Discard carry

46

You might also like