Anda di halaman 1dari 64

Chapter 1

Number systems and codes

1
Chapter outline
Analog versus Digital
Introduction to number systems
Decimal, binary, octal & hexadecimal number systems
Conversion between bases
Number representation in binary(Signed number representation)
Sign-bit magnitude
1s complement
2s complement
Radix complement & Diminished Radix complement Arithmetic
Codes

2
Analog versus Digital
Analog systems process time-varying signals that can take on any
value across a continuous range of voltages (in electrical or
electronics systems).
For example, the reading of a moving coil or moving iron voltmeter
and ammeter, dynamometer wattmeter etc., are all analog
quantities.

3
Analog versus Digital
Digital systems process time-varying signals that can take on only
one of two discrete values of voltages (in electrical/electronics
systems).
Discrete values are called 1 and 0 (ON and OFF, HIGH and LOW,
TRUE and FALSE, etc.)
Analog electronics deals with non-discrete values
Digital electronics deals with discrete values

4
Analog versus Digital
The term digital is derived from digits. Any device or system which
works on digits is a digital device or system.
A digital voltmeter indicates the value of voltage in the form of
digits, e.g., 230.25.
Reading an analog instrument introduces human error and also
requires more time.
A digital reading is more accurate, eliminates human error and can
be read quickly.
The initial signal waveform is always analog. To use digital
transmission, the signal waveform is sampled and the digital
representation transmitted.
The process of converting analog signal to digital form is also known
as digitizing. For multiple channels of transmission, Multiplexing is
used. 5
Analog versus Digital
A DSP (digital signal processing) chip is the core of digital
system used in cellular phones, modems, disk drives, digital
automotive systems etc.
It was invented only about 15 ago but its applications have
grown tremendously.

Fig. Digital System


6
Benefits of Digital over Analog
Easier to design and having higher accuracy
Programmability
Noise immunity
easier storage of data and ease of fabrication
Reproducibility
Speed
Economy

7
Introduction to number system

8
Introduction to number system

Positional Notation

Power Series Expansion

9
Introduction to number system
R is the radix or base of the number system
Must be a positive number
R digits in the number system: [0 .. R-1]
Important number systems for digital systems:
Base 2 (binary): [0, 1]
Base 8 (octal): [0 ... 7]
Base 10 (Decimal): [0 ... 9]
Base 16 (hexadecimal): [0 ... 9, A, B, C, D, E, F]

10
Introduction to number system
Decimal Number System
The decimal number system has ten digits: 0, 1, 2, 3,
4, 5, 6, 7, 8, and 9
The decimal numbering system has a base of 10 with
each position weighted by a factor of 10:

11
Introduction to number system
Binary Number System
The binary number system has two digits: 0 and 1
The binary numbering system has a base of 2 with
each position weighted by a factor of 2:

12
Introduction to number system

Number system overview

13
Conversion between Bases
Conversion of a mixed decimal number is implemented
as follows:
Convert the integer part of the number using
repeated division.
Convert the fractional part of the decimal
number using repeated multiplication.
Combine the integer and fractional
components in the new base.

14
Conversion between Bases
Conversion between any two bases, A and B, can be
carried out directly using repeated division and
repeated multiplication.
Base A Base B
However, it is generally easier to convert base A to
its decimal equivalent and then convert the decimal
value to base B.
Base A Decimal Base B

Power Series Expansion Repeated Division, Repeated Multiplication

15
Conversion of Decimal Integer
Use repeated division to convert to any base
N = 57 (decimal)
Convert to binary (R = 2) and octal (R = 8)

57 / 2 = 28: rem = 1 = a0
57 / 8 = 7: rem = 1 = a0
28 / 2 = 14: rem = 0 = a1
7 / 8 = 0: rem = 7 = a1
14 / 2 = 7: rem = 0 = a2
5710 = 718
7 / 2 = 3: rem = 1 = a3
3 / 2 = 1: rem = 1 = a4
Use power series expansion to
1 / 2 = 0: rem = 1 = a5 confirm results.
5710 = 1110012
16
Conversion of Decimal Fraction

Use repeated multiplication to convert to


any base
N = 0.625 (decimal)
Convert to binary (R = 2) and octal (R = 8)
0.625 * 2 = 1.250: a-1 = 1 0.625 * 8 = 5.000: a-1 = 5
0.250 * 2 = 0.500: a-2 = 0 0.62510 = 0.58

0.500 * 2 = 1.000: a-3 = 1


0.62510 = 0.1012 Use power series expansion to
confirm results.

17
Conversion of Decimal Fraction
In some cases, conversion results in a repeating fraction
Convert 0.710 to binary
0.7 * 2 = 1.4: a-1 = 1
0.4 * 2 = 0.8: a-2 = 0
0.8 * 2 = 1.6: a-3 = 1
0.6 * 2 = 1.2: a-4 = 1
0.2 * 2 = 0.4: a-5 = 0
0.4 * 2 = 0.8: a-6 = 0
0.710 = 0.1 0110 0110 0110 ...2
Example:
Convert 48.562510 to binary.
Confirm the results using the Power
Series Expansion. 18
Conversion of Octal
Conversion between binary and octal can be
carried out by inspection.
Each octal digit corresponds to 3 bits
101 110 010 . 011 0012 = 5 6 2 . 3 18
010 011 100 . 101 0012 = 2 3 4 . 5 18
7 4 5 . 3 28 = 111 100 101 . 011 0102
3 0 6 . 0 58 = 011 000 110 . 000 1012

Is the number 392.248 a valid octal number?

19
Conversion of Hexadecimal
Conversion between binary and hexadecimal
can be carried out by inspection.
Each hexadecimal digit corresponds to 4 bits
1001 1010 0110 . 1011 01012 = 9 A 6 . B 516
1100 1011 1000 . 1110 01112 = C B 8 . E 716
E 9 4 . D 216 = 1110 1001 0100 . 1101 00102
1 C 7 . 8 F16 = 0001 1100 0111 . 1000 11112
Note that the hexadecimal number system requires
additional characters to represent its 16 values.

20
Number Systems

21
Number representation in binary
Unsigned and Signed Numbers
bn 1 b1 b0

Magnitude

MSB
(a) Unsigned number- For an n-bit unsigned binary number,
all n bits are used to represent the magnitude of the number.
** Cannot represent negative numbers.
bn 1 bn 2 b1 b0

Magnitude
Sign
0 denotes +
1 denotes MSB

(b) Signed number 22


Number representation in binary
Unsigned Binary Numbers

1 byte = 8 bits = 28 = 256 (0 to 255)


255 decimal = 1111 1111 binary
2 bytes = 16 bits = 216 = 65,536 (0 to 65,535)
4 bytes = 32 bits = 232
= 4,294,967,296 (0 to 4,294,967,295)
23
Number representation in binary
Signed Binary Numbers
Number representation in binary
Different formats used for binary representation of
both positive and negative decimal numbers.
Three representations for signed binary numbers:

1. Sign-and-Magnitude
2. One's Complement
3. Two's Complement

25
Number representation in binary
Sign-and-Magnitude

26
Number representation in binary
Sign-and-Magnitude

Example: What is the Sign-and-Magnitude binary number


representation for the following decimal values, using 8 bits:
+ 97
- 68
Can the following decimal numbers be represented using
Sign-and-Magnitude representation and 8 bits?
- 127
+ 128
- 212
+ 255
27
Number representation in binary
Ones Complement
In the 1s complement format, the positive numbers remain
unchanged.
The negative numbers are obtained by taking the 1s
complement of the positive counterparts.
For example, +9 will be represented as 00001001 in eight-bit
notation, and 9 will be represented as 11110110, which is the
1s complement of 00001001.
Again, n-bit notation can be used to represent numbers in the
range from (2n11) to +(2n11) using the 1s complement
format. For example, the eight-bit representation of the 1s
complement format can be used to represent decimal numbers
in the range from 127 to +127.
Includes a representation for -0 and +0.
Represents an equal number of positive and negative values.
28
Number representation in binary
One's Complement
An n-bit positive number (P) is represented in the same way as
in the Sign-and-Magnitude representation.
The sign bit (MSB) = 0.
The remaining n-1 bits represent the magnitude.
An n-bit negative number (N) is represented using the One's
Complement of the equivalent positive number (P).
N' = One's Complement representation for the
negative number N.
N' = (2n 1) P; where P = |N|
The sign bit (MSB) = 1 for all negative numbers using
the One's Complement representation.
29
Number representation in binary
One's Complement
Example: Determine the One's Complement representation
for the following negative numbers, using 8 bits:
- 11
- 107
- 74
The One's Complement representation of N can also be
determined using the bit-wise complement of P.
N = n-bit negative number
P = |N|
N' = One's Complement representation of N.
N' = bit-wise complement of P
i.e. complement P, bit-by-bit. 30
Number representation in binary
One's Complement
Example: Determine the One's Complement representation
(using the bit-wise complement) for the following negative
numbers, using 8 bits:
- 11
- 107
- 74

Given a negative number (N), represented using the One's


Complement representation (N'), the magnitude of the
number (P) can be determined as follows:
P = (2n 1) N'
or
P = bit-wise complement of N' 31
Number representation in binary
Twos Complement
In the 2s complement representation of binary numbers, the MSB
represents the sign, with a 0 used for a plus sign and a 1 used for a
minus sign.
The remaining bits are used for representing magnitude.
Positive magnitudes are represented in the same way as in the case of
sign-bit or 1s complement representation.
Negative magnitudes are represented by the 2s complement of their
positive counterparts. For example, +9 would be represented as
00001001, and 9 would be written as 11110111. Please note that, if
the 2s complement of the magnitude of +9 gives a magnitude of 9,
then the reverse process will also be true, i.e. the 2s complement of
the magnitude of 9 will give a magnitude of +9.
The 2s complement format is very popular as it is very easy to
generate the 2s complement of a binary number and also because
arithmetic operations are relatively easier to perform when the
numbers are represented in the 2s complement format. 32
Number representation in binary
Two's Complement
An n-bit positive number (P) is represented in the same way as
in the Sign-and-Magnitude representation.
The sign bit (MSB) = 0.
The remaining n-1 bits represent the magnitude.
An n-bit negative number (N) is represented using the Two's
Complement of the equivalent positive number (P).
N* = Two's Complement representation for the
negative number N.
N* = (2n) P
where P = |N|
The sign bit (MSB) = 1 for all negative numbers using
the Two's Complement representation. 33
Number representation in binary
Two's Complement
Example: Determine the Two's Complement representation
for the following negative numbers, using 8 bits:
- 11
- 107
- 74
The Two's Complement representation is related to the
One's Complement representation as follows:

N' = (2n 1) P
N* = (2n) P
N* = N' + 1
34
Number representation in binary
Two's Complement
The Two's Complement representation of N can also be
determined by adding 1 to the One's Complement
representation of N.
N = n-bit negative number
P = |N|
N' = One's Complement representation of N.
N' = bit-wise complement of P.
N* = N' + 1

Example: Determine the Two's Complement representation


(using the One's Complement) for the following negative
numbers, using 8 bits:
- 11
- 107
- 74 35
Number representation in binary
Two's Complement

Includes only one representation for 0.


Represents an additional negative value.
Given a negative number (N), represented using the Two's
Complement representation (N*), the magnitude of the
number (P) can be determined as follows:
P = (2n) N*
or
P = bit-wise complement of N* + 1
36
Signed Binary Numbers

37
1s and 2s complement
The 1s complement of a binary number is obtained by
complementing all its bits, i.e. by replacing 0s with 1s and 1s with
0s. For example, the 1s complement of (10010110)2 is
(01101001)2. The 2s complement of a binary number is obtained
by adding 1 to its 1s complement. The 2s complement of
(10010110)2 is (01101010)2.

9s and 10s complements


Corresponding to the 1s and 2s complements in the binary
system, in the decimal number system we have the 9s and 10s
complements. The 9s complement of a given decimal number is
obtained by subtracting each digit from 9. For example, the 9s
complement of (2496)10 would be (7503)10. The 10s complement is
obtained by adding 1 to the 9s complement. The 10s
complement of (2496)10 is (7504)10.
38
7s and 8s complements
In the octal number system, we have the 7s and 8s complements.
The 7s complement of a given octal number is obtained by
subtracting each octal digit from 7. For example, the 7s
complement of (562)8 would be (215)8. The 8s complement is
obtained by adding 1 to the 7s complement. The 8s complement
of (562)8 would be (216)8.

15s and 16s complements


The 15s and 16s complements are defined with respect to the
hexadecimal number system. The 15s complement is obtained
by subtracting each hex digit from 15. For example, the 15s
complement of (3BF)16 would be (C40)16. The 16s complement is
obtained by adding 1 to the 15s complement. The 16s
complement of (2AE)16 would be (D52)16.
39
Binary Arithmetic
We all are familiar with the arithmetic operations such as
additions, subtraction, multiplication and division of decimal
numbers.
Similar operations can be performed on binary numbers.
Binary arithmetic is much simpler than decimal arithmetic
because here only two digits, 0 and 1 are involved.
Binary addition:
0 0 1 1
+ 0 + 1 + 0 + 1
0 1 1 10

Sum Carry Sum


Examples:

01011011
+ 01110010 10110101 00111100
11001101 + 01101100 + 10101010
40
Binary Arithmetic
Binary Subtraction:
Borrow

0 10 1 1
- 0 - 1 - 0 - 1
0 1 1 0

Difference
Examples:

01110101 10110001 00111100


- 00110010 - 01101100 - 10101100
01000011

41
Binary Arithmetic
Binary Multiplication
0 0 1 1
x 0 x 1 x 0 x 1
0 0 0 1

Product

Examples:

10110001 00111100
x 01101101 x 10101100

42
Binary Arithmetic

Binary Division: division in binary system follows the same


long division procedure as in decimal system.

Examples: (a) Divide 110110 by 101


(b) Convert (110110)2 and (101)2 into equivalent decimal
number obtain division, convert results into binary and
compare the results with those in part (a).
Exercise: Divide 11110 by 1001

43
Radix complement & Diminished Radix
complement Arithmetic
Complements
Complements are used in digital computers for simplifying the
subtraction operation and for logic manipulation.
There are two types of complements for each base r system: radix
complement and the diminished radix complement.
The first is referred to as the rs complement and the second as the
(r-1)s complement.
When the values of the base r is substituted in the name, the two
types are referred to as the 2s complement, and 1s complement for
binary numbers , and the 10s complement, and 9s complement for
decimal numbers.

44
Two's Complement Addition
Addition of n-bit signed numbers using Two's Complement
addition is straightforward.
Addition is carried out in the same way as the addition of n-bit
positive numbers.
Carry from the sign position (MSB) is ignored.
Overflow occurs if the correct result (including the sign) cannot
be represented in n bits.
Example: Implement the addition of the following signed numbers
using Two's Complement Addition:
32 + 45
-17 + 63
82 + (-29)

45
Two's Complement Subtraction
A B = A + (-B)
Subtraction can be implemented using addition.
Determine the Two's Complement representation for
the negative number -B.
Use Two's Complement Addition to add A and -B.

Example: Implement the subtraction of the following


signed numbers using Two's Complement Addition:

32 - 45
-17 - 63
82 - (-29)

46
One's Complement Addition
Similar to the addition of n-bit numbers using Two's
Complement Addition.
Instead of discarding the carry from the sign position (MSB),
it must be added to the least significant bit (LSB) of the n-bit
sum.
Referred to as an end-around carry.

Example: Implement the addition of the following signed


numbers using One's Complement Addition:

32 + 45
-17 + 63
82 + (-29)

47
10's Complement Addition

Example: Using 10s complement, subtract 72532-3250


Example: Using 10s complement, subtract 3250-72532

16's Complement Addition


Example: Subtract (1FA)16 from (2DC)16 using the 16s complement
Exercise: Subtract (2DC)16 from (1FA)16 using the 16scomplement

48
Overflow
General rule for detecting overflow when adding two n-bit
numbers using either One's Complement or Two's
Complement Addition
An overflow occurs when the addition of two
positive numbers results in a negative value or the
addition of two negative numbers results in a
positive value.
Cannot occur when adding a positive number and a
negative number.
By using bit fields sufficiently large to handle the magnitude
of the sums, we arrive at the correct answers.

49
Binary codes
A computer is a digital system that stores and processes different
types of data in the form of 0s and 1s.
The different types of data handled by a computer system include
numbers, alphabets and some special characters.
Although, in every code used the information is represented in
binary form, the interpretation of this binary information is possible
only if the code in which this information is available is known.
Different types of codes have been developed and used to represent
the data entered by the users in the binary format.

The binary system represents each type of data in terms of binary


digits, 0s and 1s.

Since these codes convert the data into the binary form, the
computer codes are also referred as binary codes.
50
Binary codes
Binary Coded Decimal(BCD)
The binary coded decimal (BCD) is a type of binary code used to
represent a given decimal number in an equivalent binary form.

BCD-to-decimal and decimal-to-BCD conversions are very easy and


straightforward. It is also far less cumbersome an exercise to
represent a given decimal number in an equivalent BCD code than
to represent it in the equivalent straight binary form.

The BCD equivalent of a decimal number is written by replacing


each decimal digit in the integer and fractional parts with its four-
bit binary equivalent. As an example, the BCD equivalent of
(23.15)10 is written as (0010 0011.0001 0101)BCD.

51
Binary codes
BCD-to-Binary Conversion
A given BCD number can be converted into an equivalent binary
number by first writing its decimal equivalent and then converting
it into its binary equivalent.
Example:
Find the binary equivalent of the BCD number 000101001.0111 0101

Solution:

52
Binary codes
Binary-to-BCD Conversion
The process of binary-to-BCD conversion is the same as the
process of BCD-to-binary conversion executed in reverse order.
A given binary number can be converted into an equivalent
BCD number by first determining its decimal equivalent and
then writing the corresponding BCD equivalent.

Example:
Find the BCD equivalent of the binary number 10101011.101
Solution:
Corresponding decimal number: 171.625
the BCD equivalent of the binary number can be then written
as 000101110001.011000100101

53
Binary codes
Excess-3 BCD Code

54
Binary codes
Gray Codes
Code values for successive decimal digits differ in
exactly one bit.
Example: 2 - bit Gray Code
Decimal

0 00 00
1 01 01
2 10 11
3 11 10

55
Binary codes
Example: 3 - bit Gray Code
Decimal

0 000 000
1 001 001
2 010 011
3 011 010
4 100 110
5 101 111
6 110 101
7 111 100

56
Example: 4-bit Gray Code
Decimal Equivalent Binary Code Gray Code
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
57
15 1111 1000
Binary codes
Binary to Gray code conversion
We can convert a number represented in the binary form to Gray
code representation. For carrying out this conversion, we need to
remember the following two rules:
Binary Binary Gray
i. The Most Significant Bit (MSB) of Digit Addition Coded
Operation Digit
the binary number and the gray
coded number is always the same. 1 1

ii. The next MSD of the gray coded 0 1+0 1


number can be obtained by adding 1 0+1 1
the subsequent pair of bits of the
binary number starting from the 0 1+0 1
left. 0 0+0 0
Convert the binary number 0 0+0 0
10100011 to its equivalent Gray 1 0+1 1
coded number.
1 1+1 0
Binary codes
Gray to binary code conversion
We can convert the Gray coded number to its binary equivalent by
remembering the following two major rules:
i. The Most Significant Bit (MSB) of Gray Binary Binary
the Gray coded number and the Coded Addition Digit
equivalent binary number is always Digit Operation
the same. 1 1
ii. The next-to-most significant bit of 1 1+1 0
the binary number can be
determined by adding the MSB of 0 0+0 0
the binary number to the next-to-
most significant bit of the gray 1 1+0 1
coded number. 0 0+1 1

0 0+1 1

1 1+1 0

1 1+0 1
Binary codes
ASCII Code
American Standard Code for Information Interchange
Common code used for the storage and transfer of
alphanumeric characters.
7-bit Weighted Code
Can represent a total of 128 characters
Used to represent letters, numbers and other characters
(e.g. special control characters)
Any word or number can be represented (and stored or
transferred) using its ASCII Code.

60
Binary codes
Contd
The ASCII code is pronounced as ASKEE and is used for the
same purpose for which the EBCDIC code is used. However,
this code is more popular than EBCDIC code as unlike the
EBCDIC code this code can be implemented by most of the
non-IBM computer systems.

Initially, this code was developed as a 7-bit BCD code to


handle 128 characters but later it was modified to an 8-bit code.

61
ASCII Code

62
Binary codes
EBCDIC Code
Extended Binary Coded Decimal Interchange Code
(EBCDIC)
The EBCDIC code is an 8-bit alphanumeric code that was
developed by IBM to represent alphabets, decimal digits and
special characters, including control characters.
The EBCDIC codes are generally the decimal and the
hexadecimal representation of different characters.
This code is rarely used by non IBM-compatible computer
systems.

63
Lab Experiments
EXPERIMENT 1: Realization of gates using discrete components and verification of
truth table of logic gates
Experiment 2: Sum of products and Products of sums circuits.
Experiment 3: Adders and Subtractor
Experiment 4: Addition/ Subtraction in 2`s Complement Representation
Experiment 5: BCD 7- segment decoder
Experiment 6: Design of code converters (binary to Gray and Gray to binary conversion
Experiment 7: Design combinational circuits using multiplexer
Experiment 8: Design combinational circuits using demultiplexer
Experiment 9: Flip Flops
Experiment 10:Modes of registers
Experiment 11: Application of registers: ring counter, twisted-ring counter
Experiment 12: Sequence generator
Experiment 13: Asynchronous counters
Experiment 14: Synchronous Counter Design

64

Anda mungkin juga menyukai