You are on page 1of 65

CHAPTER ONE:

INTRODUCTION TO DIGITAL SYSTEMS,

NUMBER SYSTEMS AND CODES

1
1.1 ANALOG AND DIGITAL REPRESENTATION
❑ Analog system process information that varies continuously.
 They process time varying signals that can take on any values across a continuous range.
 Examples of analog quantities : time, pressure, sound.

2
…1.1 ANALOG AND DIGITAL REPRESENTATION
❑ Digital systems use digital circuits that can process digital signals which can
take either 0 or 1 for binary system.
 A discrete set of values.
 Varies in discrete (separate) steps.

3
…1.1 ANALOG AND DIGITAL REPRESENTATION
Analog Digital
❑ Use base 10 (decimal) ❑ Use base 2 (binary)
❑ Represented by 10 different level : ❑ Represented by 2 different level: 0 & 1 or
0,1,2,3,4,5,6,7,8,9 low & high.
❑ Analog system: A combination of devices that ❑ Digital system: A combination of devices that
manipulate values represented in analog form manipulate values represented in digital form.

4
5

…1.1 ANALOG AND DIGITAL REPRESENTATION


❑ Digital technology is widely used.
Advantages of digital
❑ Examples:
 Ease of design
• Computers
 Ease of storage
• Manufacturing systems
• Medical Science
 Accuracy & precision are easier to maintain
• Transportation  Programmable operation (W/t changes Hardware)
• Entertainment  Less affected by noise
• Telecommunications  Ease of fabrication on IC chips
 Their systems is more efficient & reliable:
- Data Processing
- Data Transmission
- Data Storage
6

…1.1 ANALOG AND DIGITAL REPRESENTATION


Disadvantages of digital
 Takes time to convert and process values

 Digital systems have significant electrical limitations

◼ (Cannot handle large current or high voltage)

 Can become quite complex with an increase of significant digits

 Not a completely accurate representation of analog values (rounding errors)

 Often need to convert to / from analog systems (ADC/DAC)

 More complex circuitry

 More sensitive to environmental issues (noise, electrical, temperature, etc.)


7

1.2. BINARY DIGITS, LOGIC LEVELS, & DIGITAL WAVEFORMS


❑ Digital electronics involves circuits and systems in two possible states.
▪ A HIGH and a LOW.

❑ In digital systems such as computers combinations of the two states, called


codes.

❑ They are used to represent numbers, symbols, alphabetic characters, and


other types of information.

❑ The two-state number system is called binary,


 Its two digits are 0 and 1.
 A binary digit is called a bit.
8

…1.2. ….BINARY DIGITS


❑ In digital circuits, two different voltage levels are used to represent the two bits.
❑ If, 1 is represented by the higher voltage, and a 0 is represented by the lower
voltage level it is called positive logic.
 HIGH = 1 and LOW = 0.
❑ If, 1 is represented by a LOW and a 0 is represented by a HIGH is called negative
logic.
❑ Groups of bits (combinations of 1s and 0s), called codes.
9

…1.2. ...LOGIC LEVELS


❑ The voltages used to represent a 1 and a 0 are called logic levels.
❑ Ideally, one voltage level represents a HIGH and another voltage level
represents a LOW.
❑ In a practical digital circuit,
 A HIGH can be any voltage between a specified min. & max. value.
 A LOW can be any voltage between a specified min. & max. value.

Bit 1 : 2 to 5V(high)
Bit 0 : 0 to 0.8V(low)
 There are no overlap b/n
Undefined :0.8 to 2V
the accepted range of
HIGH & LOW levels.
10

… 1.2. …DIGITAL WAVEFORMS


❑ Digital waveforms consist of voltage levels that are changing back and
forth between the HIGH and LOW levels or states.
❑ A digital waveform is made up of a series of pulses.

❑ Examples of digital
❑ waveforms :
11

… 1.2. …FREQUENCY VS PERIOD


❑ Frequency (f) is the rate at which it repeat itself at a fixed interval.
❖ Is measured in cycles per second or Hertz (Hz), 𝑓 = 1/𝑇 𝐻𝑧

❑ Period (T) is the time from the edge of one pulse to the corresponding edge
of the next pulse.
❖ Is measured in second 𝑇 = 1/𝑓 𝑠
❑ Example: clock frequency: 𝑓 = 100𝐻𝑧,
𝑠𝑜, 𝑇 = 1/100𝐻𝑧 = 0.01𝑠 = 10𝑚𝑠
❑ An important characteristics of a periodic wave form is its duty cycle,
❖ which is the ratio of the pulse width (tw) to the period.
𝐷𝑢𝑡𝑦 𝑐𝑦𝑐𝑙𝑒 = 𝑡𝑤/𝑇 ≤100%
12

… 1.2. …FREQUENCY VS PERIOD EXAMPLE


1. A portion of a periodic digital waveform is shown in Figure below. The

measurements are in milliseconds. Determine the following:


(a) period (b) frequency (c) duty cycle

a. 𝑇 𝑖𝑠 𝑚𝑒𝑎𝑠𝑢𝑟𝑒𝑑 𝑓𝑟𝑜𝑚 𝑙𝑒𝑎𝑑𝑖𝑛𝑔 𝑡𝑜 𝑙𝑒𝑎𝑑𝑖𝑛𝑔


𝑒𝑑𝑔𝑒.
𝑇 = 10𝑚𝑠
𝑏. 𝑓 = 1/𝑇 = 1/10𝑚𝑠 = 100𝐻𝑧
𝑐. 𝐷𝑢𝑡𝑦 𝑐𝑦𝑐𝑙𝑒 = 𝑡𝑤/𝑇 ∗ 100% = 10%

2. A periodic digital waveform has a pulse width of 25 ms and a period of


150 ms. Determine the frequency and the duty cycle.
13

1.3. TYPES LOGIC FAMILIES


❑ Most electronic systems which are responsible for modern advances are
based on digital technology.
❖ All digital systems, computers and microprocessors are assembled from simple circuits
called logic circuits.
❖ The basic building blocks of logic circuits are logic gates.

❖ Logic gates themselves are simple electronic circuits comprising of diodes, transistors
and resistors.

❑ The digital integrated circuits are designed using bipolar devices or Metal
Oxide Semiconductor (MOS) or a combination of both.
❖ Logic families are mainly classified as Bipolar and Unipolar Logic Families.
14

…1.3. TYPES LOGIC FAMILIES


❑ 1. Bipolar Logic Families: It mainly uses bipolar devices like diodes,
transistors in addition to passive elements like resistors and capacitors.
❑ These are sub classified as saturated and unsaturated bipolar logic family.
❑ A. Saturated Bipolar Logic Family: In this family the transistors used
in ICs are driven into saturation. For example:
❖ Transistor-Transistor Logic (TTL)
❖ Resistor-Transistor Logic (RTL)
❖ Direct Coupled Transistor Logic (DCTL)
❖ Diode Transistor Logic (DTL)
❖ High Threshold Logic(HTL)
15

…1.3. TYPES LOGIC FAMILIES


❑ B. Unsaturated bipolar logic family: In this family the transistors used in
IC is not driven into saturation. For example:
❖ Schottky TTL
❖ Emitter Coupled Logic(ECL)
❑ 2. Unipolar Logic Families: It mainly uses Unipolar devices like MOSFETs
in addition to passive elements like resistors and capacitors.
❑ These logic families have the advantages of high speed and lower power
consumption than Bipolar families. These are classified as:
❖ PMOS or P-Channel MOS Logic Family
❖ NMOS or N-Channel MOS Logic Family
❖ CMOS Logic Family
16

…1.3. TYPES LOGIC FAMILIES


17

…1.3. TYPES LOGIC FAMILIES… FEATURES OF LOGIC FAMILIES


❑ TTL - Transistor-Transistor Logic:
❖ Standard logic family; used for the longest time.
❑ ECL - Emitter Coupled Logic:
❖ Suitable for systems requiring high-speed operations.
❑ MOS - Metal Oxide Semiconductor Logic:
❖ Suitable for systems with high component density.

❑ CMOS - Complementary Metal Oxide Semiconductor Logic:


❖ Suitable for systems with low power consumption (Very large-scale integration
(VLSI) circuits).
❖ Gradually becomes the dominant logic family.
18

1.4 DECIMAL NUMBER AND BINARY NUMBER


1. DECIMAL NUMBER
❑ The decimal numbering system has 10 digits 0 through 9.
❑ The decimal numbering system has a base of 10 with each position weighted by a factor
of 10.
….105 104 103 102 101 100. 10-110-2 10-3 10-4 10-5…
❑ Example 1: Express decimal 47 as a sum of the values of each digit : 2745.214

Positional values
(weight)
103 102 101 100 10-1 10-2 10-3

2 7 4 5 . 2 1 4

MSD Decimal points LSD

❑ Example 2: Express decimal 376 and 2,593 as a sum of the values of each digit.
…1.4 DECIMAL NUMBER AND BINARY NUMBER
2. BINARY NUMBER
❑ The binary numbering system has 2 digits 0 and 1
❑ The binary numbering system has a base of 2 with each position weighted by
a factor of 2 4 3 2 1 0 -1 -2 -3 -4 -5
2 2 2 2 2 2 2 2 2 2

increase increase

❑Example 1: the decimal equivalent of the 24 23 22 2120


binary number 101112 1 0 1 11
101112 = (1X24+0X23+1X22+1X21+ 1X20)= 23 16 0 4 2 1 19

16 + 4 + 2 + 1 = 2310
20

1.5 A) BINARY-TO-DECIMAL CONVERSION


❑ Convert binary to decimal 100101. Weights 23=8 22=4 21=2 20=1 Decimal
Equivalent

2 + 2 + 2 + 2 + 2 + 2 = 32 + 4 + 1 = 3710
5 4 3 2 1 0 0 0 0 0 0

0 0 0 1 1

0 0 1 0 2

0 0 1 1 3

0 1 0 0 4

0 1 0 1 5

0 1 1 0 6

Binary Count 0

1
1

0
1

0
1

0
7

1 0 0 1 9

1 0 1 0 10

1 0 1 1 11

1 1 0 0 12

1 1 0 1 13

1 1 1 0 14

1 1 1 1 15
21

…1.5 A BINARY-TO-DECIMAL CONVERSION


❑ Step 1: Get n, total binary numbers
❖ 1101101 ➔ n = 7 binary numbers
❑ Step 2: Conversion will stop at 2n-1 = 26

❑ Step 3: Multiply all the numbers with its appropriate weight

❑ Step 4: Sum the result from step 3, and binary is now decimal.

Example 1. 100101
❑ Step 1: Binary number: 100101 ➔ n = 6

❑ Step 2: Stop at 2n-1 = 25

❑ Step 3: multiply

❑ Step 4: sum
22

…1.5 B) DECIMAL-TO-BINARY CONVERSION


❑ Two methods to convert decimal to binary:

1) Sum-of-weights method (reverse process)

◼ Determine the set of binary weights whose sum is equal to the decimal
number

2) Repeated division-by-2 method

◼ Repeatedly dividing the decimal number by 2 and retrieving the


remainder
…1.5 B) DECIMAL-TO-BINARY CONVERSION
1) SUM-OF-WEIGHT METHOD
Binary weights
256 128 64 32 16 8 4 2 1
357 = 256 + 64 + 32 + 4 + 1 101100101

23
= 28 + 26 + 25 + 22 + 20
Binary weights
1024 512 256 128 64 32 16 8 4 2 1
1937 = 1024 + 512 + 256 + 128 + 16 + 1 11110010001
Exercises: Decimal – to – Binary conversions
a. 39810 =????

b. 415310= ????
…1.5 B) DECIMAL-TO-BINARY CONVERSION
1) SUM-OF-WEIGHT METHOD
58 AND 125 CONVERT TO BINARY NUMBER
Nearest weight to 58 125
minus
58 64
minus
32 64 32 16 8 4 1
32 16 8 2 61 Apply a 1 to these
26 Apply a 1 to these
minus
weights and 0 to others
minus
weights and 0 to others
32
16
29
10 minus
minus 16
8
13
2 minus 26 25 24 23 22 21 20
minus
25 24 23 22 21 20 8
2 64 32 16 8 4 2 1
5
0 32 16 8 4 2 1 minus
4 1 1 1 1 1 0 1
1 1 1 0 1 0
1
minus 24
5810 = 1110102 1
0
25

…1.5 B) DECIMAL-TO-BINARY CONVERSION


2. REPEATED DIVISION-BY-2
❑ Repeated division steps: ❑ Examples
a) 3710=?2
 Divide the decimal number by 2 37 2 = 18 with R of 1 1s → LSB
 Write the remainder after each division 18  2 = 9 with R of 0 2s
9  2 = 4 with R of 1 4s
until a quotient of zero is obtained. 4  2 = 2 with R of 0 8s
2  2 = 1 with R of 0 16s
 The first remainder is the LSB and the
1  2 = 0 with R of 1 32s → MSB
last is the MSB  3710= 1001012

❑ Note, when done on a calculator, a b) 39810= ?2

fractional answer indicates a


remainder of 1.
26

…1.5 B) DECIMAL-TO-BINARY CONVERSION


2. Repeated division-by-2
❑ This flowchart describes the process &
can be used to convert from decimal to
any other number system.
27

…1.5 B) DECIMAL-TO-BINARY CONVERSION


2. REPEATED DIVISION-BY-2
1210 = X2 4510 = Y2
Remainder
Remainder
Right/LSB
12 = 6 Right/LSB 45 = 22 1
0
2 2
22 = 11 0
6 = 3 0 2
2 1 1 0 0 1 0 1 1 0 1
11 = 5 1
2
3 = 1 1
2 5 = 2 1
2
1 = 0 1
Left/MSB
2 = 1 0
2
2
Stop when the 1 = 0 1
quotient = 0
2 Left/MSB
…1.5 B) DECIMAL-TO-BINARY CONVERSION
CONVERTING DECIMAL FRACTIONS-TO-BINARY
❑ 2 ways to convert:
2. Repeated multiplication by 2
1) Sum-of-weight
❑ Conversion of decimal-binary
2) Repeated multiplication of 2
 Whole numbers ➔ repeated division by 2
1. Sum-of-weight
 Fractions ➔ repeated multiplication by 2
2-1 2-2 2-3 2-4 ❑ Step 1: multiply number by 2
0.5 0.25 0.125 0.0625 ❑ Step 2: note the carry (1 or 0)
divide by 2 from ❑ Step 3: repeat with new fraction
previous value 28

❑ Stop when fraction part = 0


29

…1.5 B) DECIMAL-TO-BINARY CONVERSION


2) REPEATED MULTIPLICATION BY 2
carry
left/MSB
0.3125 x 2 = 0.625 0

0.625 x 2 = 1.25 1
.0 1 0 1

0.25 x 2 = 0.50 0

0.50 x 2 = 1.00 1
right/LSB

stop when fractional


part = 0 OR
continue until desired
number of decimal
places
…1.5 B) DECIMAL-TO-BINARY CONVERSION
❑ Using Sum-of-weights convert to Binary weights 95.6875

64 32 16 8 4 2 1 .5 .25 .125 .0625

95.6875 = 64 + 16 + 8 + 4 + 2 + 1 + .5 + .125 + .0625

1011111.1011

30
❑ Repeated division by 2 yields the whole number while repeated
multiplication by 2 of the fraction yields the binary fraction.
1

1.6 HEXADECIMAL NUMBER AND OCTAL NUMBER


1. HEXADECIMAL NUMBER SYSTEM
❑ Most digital systems deal with groups of bits in even powers of 2 such as 8,
16, 32, and 64 bits.
❑ Hexadecimal uses groups of 4 bits.

❑ Base 16

 16 possible symbols
 0-9 and A-F
❑ Allows for convenient handling of long binary strings.

❑ Convert from hex to decimal by multiplying each hex digit by its positional
weight.
2

…1.6 HEXADECIMAL NUMBER AND OCTAL NUMBER


DECIMAL-TO-HEX CONVERSION
❑ Convert from decimal to hex by using the repeated division method used for

decimal to binary and decimal to octal conversion.


❑ Divide the decimal number by 16
❑ The first remainder is the LSB and the last is the MSB.
 Note, when done on a calculator a decimal remainder can be multiplied by 16 to get
the result.
 If the remainder is greater than 9, the letters A through F are used.
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
3

…1.6 HEXADECIMAL NUMBER AND OCTAL NUMBER


❑ Example of hex to binary conversion. 9F216 = 9 F 2
EXAMPLE = 1001 1111 0010
= 1001111100102

Decimal-to-Hex
4

…1.6 HEXADECIMAL NUMBER AND OCTAL NUMBER


BINARY-TO-HEX CONVERSION

❑ Convert from binary to hex by grouping bits in four starting with the LSB.
❑ Each group is then converted to the hex equivalent.
❑ Leading zeros can be added to the left of the MSB to fill out the last group.
❑ Example of binary to hex conversion.
❑ 11101001102 = 0011 1010 0110
= 3 A 6
= 3A616

❑ Counting in hex requires a reset and carry after reaching F.


…1.6 HEXADECIMAL NUMBER AND OCTAL NUMBER
2. OCTAL NUMBER
❑ The Octal Number System:

 uses base 8
 includes only the digits 0 through 7

❑ The Octal system is based on the binary system with a 3-bit boundary

85 84 83 82 81 80
32768 4096 512 64 8 1
❑ Convert octal number to decimal number.

35
…1.6 HEXADECIMAL NUMBER AND OCTAL NUMBER
OCTAL NUMBER
 Binary-to-Octal Conversion
001 010 111 110 110 010
 (ex : 10101111101100102) 1 2 7 6 6 2
 Octal-to-Binary Conversion
1 2 7 6 6 2
 (ex : 1276628)
001 010 111 110 110 010

36
7

1.7 SIGNED NUMBERS


❑ A signed binary number consists of both sign and magnitude information.

❑ The sign indicates whether a number is positive or negative and the


magnitude is the value of the number.

❑ There are three forms in which signed integer (whole) numbers can be
represented in binary:
❖ Sign-magnitude,
❖ 1's complement, and
❖ 2's complement.

❑ The 2's complement is the most important and the sign-magnitude is


rarely used.
8

1.7 SIGNED NUMBERS


The Sign Bit
❑ The left-most bit in a signed binary number is the sign bit, which tells you whether the
number is positive or negative.
❑ a 0 is for positive, and a 1 is for negative

Sign-Magnitude Form
❑ When a signed binary number is represented in sign-magnitude, the left-most bit is the
sign bit and the remaining bits are the magnitude bits.
❑ For example, the decimal number +25 is expressed as an 8-bit signed binary number using
the sign-magnitude form as
00011001 Sign bit Magnitude bits
❑ The decimal number −25 is expressed as 10011001
❑ Notice that the only difference between +25 and -25 is the sign bit because the magnitude
bits are in true binary for both positive and negative numbers
❑ In the sign-magnitude form, a negative number has the same magnitude bits as the
corresponding positive number but the sign bit is a 1 rather than a zero.
9

…1.7 SIGNED NUMBERS


1‘S & 2‘S COMPLIMENT OF BINARY NUMBER
❑ For the Binary number (base-2) system, there are two types of complements: 1’s
complement and 2’s complement.
10110010 Binary number
1’s Complement of a Binary Number       
❑ To get 1’s complement of a binary number, 01001101 1’s complement
 simply invert the given number.
2’s Complement of a Binary Number
❑ To get 2’s complement of a binary number,

 simply invert the given number and add 1 to the least significant bit (LSB) of given
result.
 2’s Complement = 1’s Complement +1
0

…1.7 SIGNED NUMBERS


❑ Binary numbers 1’s complement 2’s complement
❑ 0001 1110 1111
❑ 0010 1101 1110
❑ 0100 1011 1100
❑ 0110 1001 1010
❑ 1001 0110 0111
❑ 1010 0101 0110
❑ 1101 0010 0011
❑ 1110 0001 0010
❑ 1010100101 0101011010 0101011011
1

…1.7 SIGNED NUMBERS


❑ In general, the binary number can be represented in two ways.
 Unsigned Binary Numbers and Signed Binary Numbers
❑ Unsigned Binary Numbers: Using unsigned binary number representation,
only positive binary numbers can be represented.
❑ For n-bit unsigned binary numbers, all n-bits are used to represent the
magnitude of the number.

❑ For example, if we represent decimal 12 in 5- bit unsigned number form


then 12 = (01100)2.
❑ Here all 5 bit are used to represent the magnitude of the number.
2

…1.7 SIGNED NUMBERS


❑ Signed Binary Numbers: To represent negative integers, we need a
notation for negative values.

❑ It is normally to represent the sign with a bit placed in the left most position
of the number.
❑ The convention is to make the sign bit 0 for positive & 1 for negative.
❑ Three different ways the signed binary numbers represented.
❖ Signed
Magnitude, 1’s Complement & 2’s Complement Form
❑ Example: The representation of + 34 and -34 in a 8-bit sign-magnitude
form.
3

…1.7 SIGNED NUMBERS


❑ In 1’s complement, the representation of the positive number is same as the
negative number.
❑ But the representation of the negative number is different.

❑ In
2’s complement, the representation of the positive number is same as 1’s
complement and sign-magnitude form.
4

…1.7 SIGNED NUMBERS


…1.7 SIGNED NUMBERS
Methods of obtaining the 2's complement of a number:
❑ The 2's complement of a number can be obtained in three ways as given
below.
❖ By obtaining the 1's complement of the given number (by changing all 0s to 1s
and 1s to 0s) and then adding 1.

❖ By subtracting the given n-bit number N from 2n.

❖ Starting at the LSB, copying down each bit up to and including the first 1 bit
encountered, and complementing the remaining bits.
…1.7 SIGNED NUMBERS
Example: Express -45 in 8-bit 2’s complement form. +45 in 8-bit form is 00101101.
❑ First method
❖ Obtain the 1’s complement of 00101101 and then add 1.
❖ Positive expression of the given number 00101101
❖ 1’s complement of it 11010010
❖ Add 1 +1
❖ Thus, the 2’s complement form of -45 is 11010011
❑ Second method
Subtract the given number N from 2n
2n = 100000000
Subtract 45 = − 00101101
Thus, the 2’s complement form of -45 is 11010011
❑ Thirdmethod
❑ Copy down the bits starting from LSB up to and including the first 1, and then
complement the remaining bits.
Original number 00101101
Copy up to first 1 bit 1
Complement the remaining bits 1101001
Thus, the 2’s complement form of -45 is 11010011
47
…1.7 SIGNED NUMBERS
Two's Complement Arithmetic
❑ The 2's complement system is used to represent negative numbers using modulus
arithmetic.
❑ The word length of a computer is fixed.

❑ That means if a 4-bit number is added to another 4-bit number, the result will be only of 4
bits. Carry, if any, from the fourth bit will overflow.
❑ This is called the modulus arithmetic. Example: 1100 + 1111 = 1011.
❑ In the 2's complement subtraction, add the 2's complement of the subtrahend to the
minuend.
❑ If there is a carry out, ignore it. Look at the sign bit, i.e. MSB of the sum term.
❑ If the MSB is a 0, the result is positive and it is true binary form.

❑ If the MSB is a 1 (whether there is a carry or no carry at all) the result is negative and is in
its 2's complement form.
❑ Take its 2's complement to find its magnitude in binary.
…1.7 SIGNED NUMBERS
Example: subtract 14 from 46 using the 8-bit 2’s complement arithmetic.
+14 = 00001110
−14 = 11110010 (in 2’s complement form)
+46 00101110
−14  +11110010 (2’s complement form of−14)
+32 100100000 (Ignore the carry)
❑ There is a carry, ignore it.
❑ The MSB is 0; so, the result is positive and is in normal binary form.
❑ Therefore, the result is +00100000=+32
…1.7 SIGNED NUMBERS
Example: add −75 to +26 using the 8-bit 2’s complement arithmetic
+75 = 01001011
−75 = 10110101 (in 2’s complement form)
+26 00011010
−75  +10110101 (2’s complement form of -75)
−49 11001111 (No carry)
❑ There is no carry, the MSB is a 1.

❑ So, the result is negative and is in 2’s complement form.

❑ The magnitude is 2’s complement of 11001111, that is, 00110001=49.

❑ Therefore, the result is −49.


…1.7 SIGNED NUMBERS
One's Complement Arithmetic
❑ The 1's complement of a number is obtained by simply complementing each bit of the
number, that is, by changing all the 0s to 1 s and all the 1 s to 0s.
❑ One of the difficulties of using 1's complement is its representation of zero.
❑ Both 00000000 and its 1's complement 11111111 represent zero.
❑ The 00000000 is called positive zero and the 11111111 is called negative zero.
❑ In 1's complement subtraction, add the 1's complement of the subtrahend to the minuend.
❑ If there is a carry out, bring the carry around and add it to the LSB. This is called the end
around carry.
❑ Look at the sign bit (MSB); if this is a 0, the result is positive and is in true binary.
❑ If the MSB is a 1 (whether there is a carry or no carry at all), the result is negative and is
in its 1's complement form. Take its 1's complement to get the magnitude in binary.
…1.7 SIGNED NUMBERS
Example: subtract 14 from 25 using the 8-bit
Example: Add −25 to 14 using the 8-bit 1’s
1’s complement arithmetic
complement method.
Solution Solution
+25 00011001 +14 00001110
−14  +11110001 (1’s form of −14) −25  +11100110 (1’s form of −25)
+11 100001010 −11 11110100 (No carry)
+1 (Add the end around carry) ❑ There is no carry, the MSB is a 1.

00001011 =+ 1110 ❑ So, the result is negative and is in its 1’s


complement form.
❑ The 1’s complement of 11110100 is
00001011.
❑ The result is, therefore, −1110.
…1.7 SIGNED NUMBERS
❑ The two numbers in addition are the addend and the augend. The result is
the sum. The 2’s compliment will be used to represent negative numbers.

❑ There are four cases that must be considered when adding two numbers:
1. Both numbers positive

2. Positive number and smaller negative number

3. Positive number and larger negative number

4. Both numbers negative

We will take one case at a time. Eight bits are used to represent each number
…1.7 SIGNED NUMBERS
1. Both numbers positive:
❖ In this case, both sign bits are zero and a 2's compliment is not required. To illustrate,
we will add +7 and +4: 7 00000111
+ 4 00000100
11 00001011

2. Positive number and smaller negative number:


❖ In this case, the true binary form of the positive number is added to the 2's complement
of the negative number.
❖ The sign bits are included in the addition, and the result will be positive. To illustrate
we will add + 15 and -6:
15 00001111
+ -6 11111010
9 100001001
Discard carry
Notice that the sign of the sum is positive (0) as it should be.
…1.7 SIGNED NUMBERS
3. Positive number and larger negative number:
❖ Again, the true binary form of positive number is added to the 2's complement of the
negative number.
❖ The sign bits are included in the addition, and the result will be negative. To illustrate
will add + 16 and - 24:
16 00010000
+ -24 11101000 (2’s complement of -24)
-8 11111000 (2’s complement of -8)
❖ Notice that the result automatically comes out in 2's complement because it is a
negative number.
4. Both numbers negative:
❖ In this case, the 2's complements of both numbers added and, of course, the sum is a
negative number in 2's complement form illustrate, we will add - 5 and -9:
-5 11111011 (2’s complement of -5)
+ -9 11110111 (2’s complement of -9)
-14 111110010 (2’s complement of -14)
Discard carry
…1.7 SIGNED NUMBERS
Overflow
❑ When the number of bits in the sum exceeds the number of bits in each of numbers
added, overflow results, as illustrated by the following example.

❑ The overflow condition can occur only when both numbers are positive or both
numbers are negative. An overflow result is indicated by an incorrect sign bit.
1.8 GRAY CODE
❑ The Gray code belongs to a class of codes called minimum change codes,

❖ Only one bit in the code group changes when going from one step to the next.

❑ The gray code is an unweighted code, meaning that the bit positions in the code
groups do not have any specific weight assigned to them.

❑ Because of this, the gray code is not suitable for arithmetic operations but finds
application in input/out put devices and some types of analog-to-digital
converters.

❑ Table below shows the gray code representation for the decimal number 0 through
15,together with straight binary code.
…1.8 GRAY CODE
❑ In Gray code only one bit of Gray code changes.
Decimal Binary Gray
❑ For example:
code code
Decimal Gray code
0 0000 0000
1 0001 0001 3 to 4 0010 to 0110
2 0010 0011
3 0011 0010
14 to 15 1001 to 1000
4 0100 0110
5 0101 0111
❑ Compare this with the binary code, where anywhere
6 0110 0101
7 0111 0100
from one to all of the bits changes in going from one
8 1000 1100
9 1001 1101
step to the next.
10 1010 1111 ❑ For example:
11 1011 1110
12 1100 1010 Decimal Binary code Gray code
13 1101 1011
14 1110 1001
7 to 8 0111 to 1000 0100 to 1100
57
15 1111 1000
…1.8 GRAY CODE
BINARY-TO-GRAY CODE CONVERSION
❑ The most significant bit (MSBt) in the Gray code is the same as the
corresponding MSB in the binary number.
❑ Going from left to right, add each adjacent pair of binary code bits to get the
next Gray code bit. Discard carries.
❑ For example, the conversion of the binary number 1110 to Gray code is as
follows:
1 + 1 + 1 + 0

1 0 0 1

= 1001 ( Gray code)


❑ The Gray code is 1001.
…1.8 GRAY CODE
GRAY -TO- BINARY CONVERSION
❑ The following rules explain how to convert from gray code to a binary number :
❑ The most significant bit (left-most) in the binary code is the same as the corresponding bit
in the Gray code.
❑ Add each binary code bit generated to the Gray code bit in the next adjacent position.
Discard carries.
❑ For example, the conversion of the Gray code word 1110 to binary is as follows:

Eg : 1110 (Gray Code)


1 1 1 0

+ + +
= 10112
1 0 1 1

The binary number is 1011.


1.9 BINARY CODED DECIMAL (BCD)
❑ BCD is a way to express each of the decimal digits with a binary code.
❑ Use four bits to represent one decimal digit.
❑ A decimal number in BCD is the same as its equivalent binary number only
when the number is between 0 and 9.

❑ The binary combinations 1010 through 1111 are not used and have no
meaning in BCD. Ex : 3510 = 0011 0101

60
…1.9 BINARY CODED DECIMAL (BCD)
BCD CONVERSION AND ADDITION
❑ There are only 10 code groups in the BCD system
0 1 2 3 4 5 6 7 8 9
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
❑ Ex

❑ BCD Addition

❑If the decimal addition has carry,


correct the results by adding 6 = 0110.
61
…1.9 BINARY CODED DECIMAL (BCD)
BCD CONVERSION AND ADDITION
❑ Consider the addition of 184 + 576 = 760 in BCD:

62
63

1.20 ASCII Code


❑ American Standard Code for Information Interchange (ASCII)

❑ It has 128 characters and symbols represented in 7-bit binary code

❑ Example :
A = 10000012;
a = 11000012
ASCII TABLE Kos ASCII : 10000012

000 001 010 011 100 101 110 111

0000 NUL DLE SP 0 @ P ` p

0001 SOH DCI ! 1 A Q a q

0010 STX DC2 " 2 B R b r

0011 ETX DC3 # 3 C S c s

0100 EOT DC4 $ 4 D T d t

0101 ENQ NAK % 5 E U e u

0110 ACK SYN & 6 F V f v

0111 BEL ETB ' 7 G W g w

1000 BS CAN ( 8 H X h x

1001 HT EM ) 9 I Y i y

1010 LF SUB * : J Z j z

1011 VT ESC + ; K [ k {

1100 FF FS , < L \ l |

1101 CR GS - = M ] m } 64

1110 SO RS . > N ^ n ~

1111 SI US / ? O _ o DEL
65
Symbol Binary Hexadecimal
2 0110010 32

0 0110000 30

Space 0100000 20

P 1010000 50

R 1010010 52

I 1001001 49

ASCII EXAMPLE: N 1001110 4E

20 PRINT A=“X”; T 1010100 54

Space 0100000 20

A 1000001 41

10000012 = 0100 00012 = 0111101 3D

4 18 “ 0100010 22

X 1011000 3B

“ 0100010 22

; 0111011 3B

You might also like