Вы находитесь на странице: 1из 25

ELEC 224 J.

Altiti
1


Goal 1

Digital & Analog Quantities
Number Systems
















ELEC 224 J. Altiti
2

Digital & Analog Quantities
Analog quantity have continuous values. The figure below shows a graph of air temperature vs time
of day.















The air temperature changes over a continues range of values. During the day the temperature
does not go from say 70
o
to 75
o
instantaneously. It takes on all the infinite values in between.
another examples of analog quantity is the sine wave shown below. Other examples are distance,
sound, time and pressure



Example of an analog electronic system is shown below





ELEC 224 J. Altiti
3


Digital quantity have discrete values. Varies in discrete (separate) steps
Digital technology is widely used. Examples:
o Computers
o Manufacturing systems
o Medical Science
o Transportation
o Entertainment
o Telecommunications
The figure below shows a graph of a digital signal .

The digital sequence of the above signal is 1010101010 in reality 5v 0v 5v 0v 5v 0v 5v 0v 5v 0v


another example of a digital signal is shown below. Note that each level represent


The digital sequence of the above signal is 11010100 in reality 5v 5v 0v 5v 0v 5v 0v 0v

Example of a system that uses digital and analog electronics is shown below



ELEC 224 J. Altiti
4

Advantages and disadvantages of both systems



Number Systems
Understanding digital systems requires an understanding of the decimal, binary, octal, and
hexadecimal numbering systems. The most familiar is the decimal number system (conventional
number system) that uses ten digits: 0,1,2,3,4,5,6,7,8, and 9.

Decimal Number System:
Base: 10

Decimal Digits: 0 1 2 3 4 5 6 7 8 9

Weights: ----- 10000 1000 100 10 1 . 0.1 0.01 0.001 0.0001 ------
----- 10
4
10
3
10
2
10
1
10
0
. 10
-1
10
-2
10
-3
10
-4

.
Example: The number 2745.214
10
.
The digit 2 is the Most Significant Digit (MSD)
The digit 4 is the Least Significant Digit (LSD)
The decimal number 2745.214 consist of seven decimal digits


The formula below is used to calculate the largest decimal number that can be represented with n
digits
Number Decimal Largest 1 Base
n

n: Number of digits
Base: Number system base (10)

With 5 decimal digits (n = 5) the largest decimal number is
99999 1 10
5






Analog Digital
Susceptible to noise Very Immune to noise
Less efficient in transmission More efficient in transmission
Less bandwidth Greater bandwidth



ELEC 224 J. Altiti
5

Example: 598.742
10
= 0598.7420
10
= 00598.74200
10
= 000598.742000
10


100 10 1 . 0.1 0.01 0.001 0.0001
10
2
10
1
10
0
. 10
-1
10
-2
10
-3
10
-4

5 9 8 . 7 4 2 0

(5x10
2
) + (9x10
1
) + (8x10
0
) + (7x10
-1
) + (4x10
-2
) + (2x10
-3
) + (0x 10
-4
)

(5x100) + (9x10) + (8x1) + (7x0.1) + (4x 0.01) + (2x0.001) + (0 x 0.0001)

500 + 90 + 8 + 0.7 + 0.04 + 0.002 + 0

= 598.742
10



Binary Number System:
Base: 2

Binary Digits (Bit): 0 1

Weights: ----- 16 8 4 2 1 . 0.5 0.25 0.125 0.0625 ------
----- 2
4
2
3
2
2
2
1
2
0
. 2
-1
2
-2
2
-3
2
-4

.
Example: 101010
2

The 1 is the Most Significant Bit (MSB)
The 0 is the Least Significant Bit (LSB)
The binary number 101010 consist of 6 Bits (Binary Digits)

What is the decimal number that is equal to the binary number 101010 ?

32 16 8 4 2 1
2
5
2
4
2
3
2
2
2
1
2
0

1 0 1 0 1 0

(1x2
5
) + (0x2
4
) + (1x2
3
) + (0x2
2
) + (1x2
1
) + (0x2
0
)

(1x32) + (0x16) + (1x8) + (0x4) + (1x2) + (0x1)

32 + 0 + 8 + 0 + 2 + 0

= 42
10
. The binary number 101010
2
= 42
10
in decimal



The formula below is used to calculate the largest decimal number that can
be represented in binary with n bits
Number Decimal Largest 1 Base
n

n: number of bits
Base: number system base (2)

With 2 bits (binary digits) the largest decimal number that can be represented in
binary is
3 1 2
2

10

That is with 2 bits, a range of decimal numbers from 0 to 3 can be represented. That
is a total of 4 binary combinations where each binary combination represent a
decimal number.


ELEC 224 J. Altiti
6


The formula below is used to calculate the range of decimal numbers (binary
combination) that can be represented in binary with n bits.

n
Base
n: number of bits
Base: number system base (2)

Example: How many decimal numbers can we represent in binary with 2 bits
4 2
2


2 1

b
1
b
0

Decimal
0 0 0
0 1 1
1 0 2
1 1 3

Example: How many bits are required to represent the decimal number 37
10

With 5 bits (binary digits) the largest decimal number is

10
5
31 1 2
and 32 (2
5
) decimal numbers (from 0 to 31) can be represented

With 6 bits (binary digits) the largest decimal number is

10
6
63 1 2
and 64 (2
6
) decimal numbers (from 0 to 63) can be represented

From the above it is obvious that 6 bits are needed to represent the decimal
number 37

Weights ----- 32 16 8 4 2 1
----- b
5
b
4
b
3
b
2
b
1
b
0


1 0 0 1 0 1

Example: The table below is for 4 bits (n =4).
b
3
b
2
b
1
b
0




ELEC 224 J. Altiti
7

Example: 1011.101
2
= 01011.101
2
= 001011.10100
2
= 0001011.101000
2


8 4 2 1 . 0.5 0.25 0.125
2
3
2
2
2
1
2
0
. 2
-1
2
-2
2
-3

1 0 1 1 . 1 0 1

(1x2
3
) + (0x2
2
) + (1x2
1
) + (1x2
0
) + (1x2
-1
) + (0x 2
-2
) + (1x 2
-3
)

(1x8) + (0x4) + (1x2) + (1x1) + (1x0.5) + (0x0.25) + (1x0.125)

8 + 0 + 2 + 1 + 0.5 + 0 + 0.125

= 11.625
10
. The binary number 1011.101
2
= 11.625
10
in decimal

and the decimal number 11.625
10
= 1011.101
2
in binary

Octal Number System:
Base: 8

Octal Digits: 0 1 2 3 4 5 6 7

Weights: ----- 4096 512 64 8 1 . 0.125 0.015625 ------
----- 8
4
8
3
8
2
8
1
8
0
. 8
-1
8
-2


Octal numbers were used in old computer systems. Now it is rarely used.

Example: 5073
8

The 5 is the Most Significant Digit (MSD)
The 3 is the Least Significant Digit (LSD)
The octal number 5073 consist of 4 octal digits

What is the decimal number that is equal to the octal number 5073 ?

512 64 8 1
8
3
8
2
8
1
8
0

5 0 7 3

(5x8
3
) + (0x8
2
) + (7x8
1
) + (3x8
0
)

(5x512) + (0x64) + (7x8) + (3x1)

2560 + 0 + 56 + 3

= 2619
10
. The octal number 5073
8
= 2619
10
in decimal





ELEC 224 J. Altiti
8

Hexadecimal Number System:
Base: 16

Hexadecimal Digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F
(10) (11) (12) (13) (14) (15)

Weights: ----- 4096 256 16 1 . 0.0625 0.00390625 ------
----- 16
3
16
2
16
1
16
0
. 16
-1
16
-2
-------.

Example: 3A91C
16
or 3A91Ch
The 3 is the Most Significant Digit (MSB)
The C is the Least Significant Digit (LSB)
The Hex number 3A91C consist of 5 hexadecimal digits

What is the decimal number that is equal to the hex number 5C3A ?

4096 256 16 1
16
3
16
2
16
1
16
0

5 C 3 A

(5x16
3
) + (Cx16
2
) + (3x16
1
) + (Ax16
0
)

(5x4096) + (12x256) + (3x16) + (10x1)

20480 + 03072 + 48 + 10

= 23610
10
. The Hexadecimal number 5C3A
16
= 23610
10
in decimal

Binary Coded Decimal (BCD) Number System
Binary Coded Decimal (BCD) is another way to present decimal numbers in binary form. BCD is
widely used and combines features of both decimal and binary systems. Each decimal digit is
converted to a 4 bit binary equivalent.

Decimal Digit BCD Equivalent
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

Example: What is the decimal number that is equal to the 100001110100
BCD

1000 0111 0100
8 7 4
So the BCD 100001110100 is equal to the decimal number 874

Example: What is the BCD equivalent to the decimal number 1095 ?
1 0 9 5
0001 0000 1001 0101
So the decimal number 1095 has a BCD equivalent of 0001000010010101


ELEC 224 J. Altiti
9

Gray Code
has the property that only one bit changes from one number to the next in the sequence. The gray
code is used in applications where numbers change rapidly.























The table shows the representations of decimal numbers in Binary, Octal, Hexadecimal, BCD
and Gray code.






















Decimal Binary Gray
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Decimal Binary Octal Hexadecimal BCD Gray
0 0000 0 0 0000 000
1 0001 1 1 0001 0001
2 0010 2 2 0010 0011
3 0011 3 3 0011 0010
4 0100 4 4 0100 0110
5 0101 5 5 0101 0111
6 0110 6 6 0110 0101
7 0111 7 7 0111 0100
8 1000 10 8 1000 1100
9 1001 11 9 1001 1101
10 1010 12 A 0001 0000 1111
11 1011 13 B 0001 0001 1110
12 1100 14 C 0001 0010 1010
13 1101 15 D 0001 0011 1011
14 1110 16 E 0001 0100 1001
15 1111 17 F 0001 0101 1000


ELEC 224 J. Altiti
10

ASCII Code
ASCII American Standard Code for Information Interchange. Each code represents a character
or function found on a computer keyboard. ASCII code is used to transfer information between
computers
and printers, and for internal storage.

The ASCII code is a seven bit code. With 7 bits there are 128 possible combinations.
2
7
= 128 possible codes (from 0 to 127)





The Extended ASCII code (80h to FFh or 128
10
to 255
10
) represent non-English alphabetic
characters such as:
- Currency symbols
- Greek letters
- Math symbols
- Drawing characters
- Bar graphing characters
- Shading characters

The following web site has the complete ASCII table http://www.lookuptables.com/



ELEC 224 J. Altiti
11


Conversion between Number Systems

The Figure below demonstrate the various possible conversion between number systems


















g 3 bits : Group every 3 bits g 4 bits : Group every 4 bits
f 3 bits : Form 3 bits for every octal digit f 4 bits : Form 4 bits for each hexadecimal digit

The following terms are used in digital systems Bit, Nibble, Byte, KiloByte, MegaByte and GigaByte

- Bit: a single binary digit.
Example: 1 or 0

- Nibble: a group of 4 binary digits (4 bits). 15
10
is the maximum decimal number that can be
represented with one nibble.
Example: 1101

- Byte: a group of 8 binary digits (8 bits). 255
10
is the maximum decimal number that can be
represented with one byte.
Example: 10110101

- Word: a group of 16 binary digits (16 bits). 65535 is the maximum decimal number that can be
represented with one word.
Example: 1011101101110011 = ------------------
10


- KiloBit: is 1024 binary digits (1024 bits).

- KiloByte: is 1024 Byte = 1024 x 8 bits = 8192 bits.

- MegaByte: 1024 kiloByte = 1024 x 8192 bits = 8,388,608 bits.

- GigaByte: 1024 MegaByte = 1024 x 8,388,608 bits = 8,589,934,592 bits .



ELEC 224 J. Altiti
12


Decimal to Binary Conversion

The integer portion of the decimal number will be divided by 2 repeatedly till the quotient is equal 0. The
fraction part will be multiplied by 2 till the fraction is equal 0.




Example: Convert the decimal number 25.8125 to binary.

Divison Quotient Reminder Bit
25/2 = 12 1 (LSB)
12/2 = 6 0 0
6/2 = 3 0 0
3/2 = 1 1
1/2 = 0 1 (MSB)

Multiply Integer Fraction Bit
0.8125 x 2 = 1 0.625 1 (MSB)
0.625 x 2 = 1 0.250 1
0.250 x 2 = 0 0.5 0
0.5 x 2 = 1 0 1 (LSB)

Finally 25.8125
10
= 11001.1101
2





ELEC 224 J. Altiti
13


Decimal to Octal Conversion

The integer portion of the decimal number will be divided by 8 repeatedly till the quotient is equal 0. The
fraction part will be multiplied by 8 till the fraction is equal 0.

Example: Convert the decimal number 25.8125 to octal.

Divison Quotient Reminder Digit
25/8 = 3 1/ 8 1 (LSD)
3/8 = 0 3/ 8 3 (MSD)

Multiply Integer Fraction Bit
0.8125 x 8 = 6 0.5 6 (MSD)
0.5 x 8 = 4 0 4 (LSD)

Finally 25.8125
10
= 31.64
8



Decimal to Hexadecimal Conversion

The integer portion of the decimal number will be divided by 16 repeatedly till the quotient is equal 0. The
fraction part will be multiplied by 16 till the fraction is equal 0.

Example: Convert the decimal number 25.8125 to octal.

Divison Quotient Reminder Digit
25/16 = 1 9/ 16 9 (LSD)
1/16 = 0 1/ 16 1 (MSD)

Multiply Integer Fraction Digit
0.8125 x 16 = 13 0 D (MSD)

Finally 25.8125
10
= 19.D
16



Binary to Hexasecimal Conversion

1. Starting from the Right of the binary number group every 4-bits
2. Replace each group with the hexadecimal digit equivalent

Example: Find the hexadecimal and decimal equivalent of the following binary number 100111110010 ?

Hexadecimal
1. 1001 1111 0010
2. 9 F 2

Decimal
2048 1024 512 256 128 64 32 16 8 4 2 1
2
11
2
10
2
9
2
8
2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0

1 0 0 1 1 1 1 1 0 0 1 0
= 2048 + 256 + 128 + 64 + 32 + 16 + 2 = 2,546
10


Finally 100111110010
2
= 9F2
16
= 2,546
10



ELEC 224 J. Altiti
14


Binary to Octal Conversion
1. Starting from the Right of the binary number group every 3-bits
2. Replace each group with the octal digit equivalent

Example: Find the octal equivalent of the following binary number 100111110010 ?

Hexadecimal
1. 100 111 110 010
2. 4 7 6 2

Finally 100111110010
2
= 4762
8
= 2,546
10



Hexadecimal to Binary Conversion
Replace each hexadecimal digit with its 4-bit binary equivalent (form 4-bits for each hexadecimal digit)

Example: Find the binary equivalent of the following hexadecimal number F7C9 ?

F 7 C 9
1111 0111 1100 1001

Finally F7C9
16
= 1111011111001001
2
= 63,433
10



Octal to Binary Conversion
Replace each octal digit with its 3-bit binary equivalent (form 3-bits for each octal digit)

Example: Find the binary equivalent of the following octal number 3741 ?

3 7 4 1
011 111 100 001

Finally 3741
8
= 011111100001
2
= 2,017
10



Hexadecimal to Octal Conversion
1. Convert each hexadecimal digit to its 4-bit binary equivalent.
2. follow the procedure for converting binary to octal.

Example: Find the octal equivalent of the following hexadecimal number D94A ?

1. D 9 4 A
1101 1001 0100 1010

D94Ah = 1101100101001010
2


2. 001 101 100 101 001 010
1 3 4 5 1 2


Finally D94A
16
= 1101100101001010
2
= 134512
8





ELEC 224 J. Altiti
15


Octal to Hexadecimal Conversion
1. Convert each octal digit to its 3-bit binary equivalent.
2. follow the procedure for converting binary to hexadecimal.

Example: Find the hex equivalent of the following octal number 647 ?

1. 6 4 7
110 100 111

647
8
= 110100111
2


2. 0001 1010 0111
1 A 7


Finally 647
8
= 110100111
2
= 1A7
16


Binary to Gray Code Conversion
1. The MSB in Gray code is the same as the corresponding MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary code bits to get the next gray code bit.
Discard Carries

Binary addition


1
0
+
0
0
0
+
1
1
1
+
0
1
+
0
1
1
1

Example: Convert 10110
2
to Gary code.

1 + 0 + 1 + 1 + 0 Binary
1 1 1 0 1 Gray

Finally 10110
2
= Gray code 11101

Gray to Binary Code Conversion
1. The MSB in the binary number is the same as the corresponding bit in the Gray code.
2. Add each binary bit generated to the Gray code bit in the next adjacent position. Discard carries.

Example: Convert the Gary code 11011 to binary .


1 0
+
1 1
0 1
0 1
+ +
0
1
+
Gray
Binary

Finally Gray code 11011 = 10010
2
= 18
10



ELEC 224 J. Altiti
16


Signed Numbers

Since it is only possible to show magnitude with a binary number, the sign (+ or -) is shown by adding an
extra sign bit.
A sign bit of 0 indicates a positive number.
A sign bit of 1 indicates a negative number.

There are 2 methodes to represent signed numbers
Sign-magnitude System
2s complement system

Sign-magnitude System
The last bit is the sign bit and does has no weight. It is used indicate the sign (+ or -). The remaining bits
corresponds to the number value.

Example:









Although the sign-magnitude system is straight forwad, computers and calculators do not normally use it,
because the circuit implementation is complex.

2s complement System
The 2s complement system is the most commonly used way to represent signed numbers.

To change the sign of a binary number perform the 2s complement as follows
Invert each bit. 1 to 0 and 0 to 1. This process is called the 1s complement
Add 1 to the 1s complement.

A short cut to performing 2s complement
Starting from the right of the binary number, leave all the bits unchanged till the first 1 is
encountered
Invert all the bits after the first encountered 1

A number is negated when converted to the opposite sign. A binary number can be negated by taking the 2s
complement of it.
.









ELEC 224 J. Altiti
17


Example: Find the negative of the decimal number 45 in binary using 7-bits.

45
10
= 0 1 0 1 1 0 1
2

Perform 1s complement
1 0 1 0 0 1 0
2
Add 1 to 1s complement

1 0 1 0 0 1 0
+
1
1 0 1 0 0 1 1 = -45
10


Finally + 45
10
= 0 1 0 1 1 0 1
2
and - 45
10
= 1 0 1 0 0 11















Range of Values with 2s complement System

The formula below is used to calculate the minimum (negative) and the maximum (positoive)
numbers can be calculated as follows

minimum (negative) number = (2
n 1
)
maximum (positive) number = + (2
n 1
1)
n: number of bits


Example: what are the range of signed and unsigned decimal numbers that can be represented with
4-bits ?
Signed
Minimum (negative) decimal number = (2
4 1
) = (2
3
) = 8
Maximum (positive) decimal number = + (2
n 1
1) = (2
3
1) = 7

Unsigned
Maximum unsignd decimal number = 2
4
1 = 15

Finally
All signed decimal number from 8 to 7 can be represented with 4-bits.
All unsigned decimal numbers from 0 to 15 can be represented with 4-bits.


ELEC 224 J. Altiti
18


The figure below demonstrate the signed and unsigned decimal numbers represented with
4-bits






















ELEC 224 J. Altiti
19


Arithmetic Operations with Signed numbers

The basic arithmetic operations are Addition and Subtraction In this sections only Binary, Hexadecimal and
BCD arithmetic operations will be discussed.

Binary Addition

The parts of any addition function are:
1. Augend
2. Addend
3. Sum

Four conditions for adding numbers:
1. Both numbers are positive.
2. A positive number that is larger than a negative number.
3. A negative number that is larger than a positive number.
4. Both numbers are negative.

Signs for Addition
1. When both numbers are positive, the sum is positive.
2. When the larger number is positive and the smaller is negative, the sum is positive. The carry is
discarded.


ELEC 224 J. Altiti
20
3. When the larger number is negative and the smaller is positive, the sum is negative (2s
complement form).
4. When both numbers are negative, the sum is negative (2s complement form). The carry bit is
discarded.

Example: Add 9
10
to 4
10
in binary .

9
10
= 001011
2

4
10
= 000100
2













Finally 9
10
+ 4
10
= 13
10
= 01101
2






Example: Add 9
10
to -4
10
in binary.

9
10
= 01001
2

-4
10
= 11100
2










Finally 9
10
+ (-4
10
) = 5
10
= 0101
2









ELEC 224 J. Altiti
21

Example: Add -9
10
to 4
10
in binary.

-9
10
= 10111
2

4
10
= 00100
2

Finally -9
10
+ 4
10
= -5
10
= 11011
2









Example: Add -9
10
and -4
10
in binary.

-9
10
= 10111
2

-4
10
= 11100
2








Finally -9
10
+ (-4
10
) = -13
10
= 10011
2


Example: Add -9
10
and 9
10
in binary.

-9
10
= 10111
2

9
10
= 01001
2








Hexadecimal Addition

1. Add the hex digits in decimal.
2. If the sum is 15 or less express it directly in hex digits.
3. If the sum is greater than 15, subtract 16 and carry 1 to the next position.
4. When the MSD in a hex number is 8 or greater, the number is negative. When the MSD is 7 or
less, the number is positive.



ELEC 224 J. Altiti
22


Example: Add 25
10
to 30
10
in hexadecimal.

25
10
= 19
16

30
10
= 1E
16


Finally 25
10
+ 30
10
= 55
10
= 37
16
Example: Add A734865
16
to 1259D6
16
.


Example: Add 34A87BC
16
to 12DF458
16
.


BCD Addition

1. Convert each BCD number to its 4-bit binary equivalent.
2. Add the two BCD numbers using the binary addition.
3. If the sum of two BCD numbers is less than or equal to 9, the sum is a valid BCD number.
4. If the sum of two BCD numbers is greayer than 9, a binary 6 is added. This will always cause a
carry.

Example: Add the 8 to 5 using BCD.

8 1000
+5 +0101
13 1101 is 13 ( > 9)








Note that the result is MORE THAN 9, so add 6.



ELEC 224 J. Altiti
23
8 1 0 0 0
+5 + 0 1 0 1
13 1 1 0 1 is 13 (> 9)

1 1 1 0 1 13
+ 0 1 1 0 add 6
1 0 0 1 1 0001 = 1 and 0011 = 3
0001 | 0011 Final answer (two digits) = 13

Finally adding 8
BCD
to 5
BCD
= 13
BCD









Example: Add 1897
BCD
to 2905
BCD














Finally adding 1897
BCD
to 2905
BCD
= 4802
BCD


















ELEC 224 J. Altiti
24

Binary Subtraction

The parts of any subtraction function are:
1. Minuend
2. Subtrahend
3. Difference

Subtraction is addition with the sign of the subtrahend changed.
1. The number subtracted (subtrahend) is negated by taking the 2s complement.
2. The result is added to the minuend.
3. The answer represents the difference.
4. Discard any final carry bit.

Example: Compute 13
10
- 5
10
in binary.

13
10
5
10
= 13
10
+ (-5
10
)

13
10
= 01101
2

5
10
= 00101
2
-5
10
= 11011
2




Finally 13
10
+ (-5
10
) = 8
10
= 01101
2
+ 11011
2
= 01000
2



Example: Compute 5
10
12
10
.

5
10
12
10
= 5
10
+ (-12
10
)

5
10
= 00101
2

12
10
= 01100
2
-12
10
= 10100
2











Finally 5
10
+ (-12
10
) = -7
10
= 00101
2
+ 10100
2
= 11001
2





ELEC 224 J. Altiti
25

Hexadecimal Subtraction

1. Subtract the hex digits in decimal.
2. If the sum is 15 or less express it directly in hex digits.
3. If the difference is negative, borrow 1 from next hex digit and add 16 to the differenc.

Example: Compute 84
16
2A
16








Finally 84
16
2A
16
= 5A
16




Example: Compute 4787C14
16
12DF458
16

Finally 4787C14
16
12DF458
16
= 34A87BC
16

Вам также может понравиться