DLD Chapter 1
DLD Chapter 1
DLD Chapter 1
(informatics)
1.1 introduction
In science, technology, business, and, in fact, most other fields of
endeavor, we are constantly dealing with quantities.
Quantities are measured, monitored, recorded, manipulated
arithmetically, observed, or in some other way utilized in most
physical systems.
It is important when dealing with various quantities that we be able
to represent their values efficiently and accurately.
There are basically two ways of representing the numerical value of
quantities:
Analog
Digital.
Digital Concepts
1.1.1 Analog representation
In analog representation a quantity is represented by a voltage, current, or meter
movement that is proportional to the value of that quantity.
The example are: the automobile speedometer, the common mercury
thermometer, audio microphone …..etc.
Analog quantities such as those cited above have an important characteristic: they
can vary over a continuous range of values.
If we take the temp. each hour, we are sampling the above graph
Figure 1.2
The Only major drawback when using digital techniques is:- the
real world is mainly analog.
Most physical quantities are analog in nature, and they need to be
monitored, operated on, and controlled by the system.
E.g. Temperature, Pressure, velocity, liquid levels, flow rate …etc.
We are in the habit of expressing these quantities digitally, such as
when we say that the temperature is 64°.
To take advantage of digital techniques when dealing with analog
inputs and outputs, three steps must be followed:
Convert the real-world analog inputs to digital form(by using
ADC).
Process (operate on) the digital information.
Convert the digital outputs back to real-world analog form (by
using DAC).
Continued..
As example, consider Recording of audio Using Compact disks(CDs), as
shown below:
First, sound from instruments and human voices produces an analog voltage
signal in the micro phone
Then, this analog signal is converted to digital using ADC.
The digital information is stored on the CD’s surface. Then the process shown
on the fig. below takes place during play back.
Binary Digits
Each of the two digits in the binary system, 1 and 0, is called a bit,
which is a contraction of the words binary digit.
In digital circuits, two different voltage levels are used to represent
the two bits.
Generally, 1 is represented by the higher voltage, which we will
refer to as a HIGH, and a 0 is represented by the lower voltage
level, which we will refer to as a LOW.
HIGH = 1 and LOW = 0
Groups of bits (combinations of 1’s and 0’s), called codes, are
used to represent numbers, letters, symbols, instructions, and
anything else required in a given application.
Logic Level
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, however, HIGH can be any voltage between a
specified minimum value and a specified maximum value.
Likewise, a LOW can be any voltage between a specified minimum and a
specified maximum.
Figure below illustrates the general
range of LOWs and HIGHs for a
digital circuit.
The variable VH(max) represents the
maximum HIGH voltage value, and
VH(min) represents the minimum
HIGH voltage value.
Cont…
Example 2:- Express the decimal number 568.23 as a sum of the values of
each digit.
2.2. Binary Numbers
The binary number system has two digits (bits). The two binary digits (bits) are 1
and 0.
The position of a 1 or 0 in a binary number indicates its weight.
The weights in a binary number are based on powers of two.
The right-most bit is the LSB (least significant bit) in a binary whole number and has
a weight of 2° = 1.
The weights increase from right to left by a power of two for each bit.
The left-most bit is the MSB (most significant bit).
The left-most bit is the MSB in a binary fractional number and has a weight of 2-1=
0.5.
The fractional weights decrease from left to right by a negative power of two for each
bit.
Generally, the weight structure of a binary number is
where n is the
number of bits from
the binary point.
Binary to Decimal Conversion
The decimal value of any binary number can be found by adding the weights
of all bits that are 1 and discarding the weights of all bits that are 0.
Example:-Convert the binary whole number 1101101 to decimal
Exercise:-
Decimal to Binary Conversion
a. Sum-of-Weights Method
One way to find the binary number that is equivalent to a given decimal
number is to determine the set of binary weights whose sum is equal to the
decimal number.
Example:- Convert the following decimal numbers to binary:
18
1’s and 2’s complement of Binary number
The 1's complement and the 2's complement of a binary number are important
because they permit the representation of negative numbers.
The method of 2's complement arithmetic is commonly used in computers to
handle negative numbers.
A. FINDING THE 1'S COMPLEMENT
The l's complement of a binary number is found by changing all 1s to 0s and
all 0s to 1s.
19
Signed Numbers
Digital systems, such as the computer, must be able to handle both
positive and negative 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,
l's complement, and
2' complement.
Of these, the 2's complement is the most important and the sign-
magnitude is the least used.
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 sign bit indicates a +ve number, and a 1 sign bit indicates a –ve 20
Cont….
a. 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.
The magnitude bits are in true (un complemented) binary for both positive and
negative numbers.
For example, the decimal number + 25 is expressed as an 8-bit signed binary
number using the sign-magnitude form as
Notice that the only difference between + 25 and - 25 is the sign bit.
b. 1' s Complement Form
Positive numbers in 1’s complement form are represented the same way as the
positive sign-magnitude numbers.
Negative numbers, however, are the 1's complements of the corresponding positive
numbers.
For example:- using eight bits, the decimal number -25 is expressed as the 1's
complement of +25 (0001100 I ) as 11100110 21
Cont….
c. 2 ' s Complement Form
Positive numbers in 2's complement form are represented the same way as in the
sign-magnitude and l's complement forms.
Negative numbers are the 2's complements of the corresponding positive numbers.
Again, using eight bits, let's take decimal number -25 and express it as the 2's
complement of +25 (00011001). 111O0111
In the 2's complement form, a negative number is the 2's complement of the
corresponding positive number.
Case II: Positive Number and Smaller Negative Number. Consider the addition of
+9 and -4. Remember that the —4 will be in its 2’s-complement form. Thus, +4
(00100) must be converted to -4 (11100).
Note:- The final carry bit is discarded. The
sum is positive and therefore in true (un-
23
complemented) binary.
Cont.…
Case III: Positive Number and Larger Negative Number. Consider the addition of
-9 and +4:
Note:- The sum is negative and therefore in
2's complement form.
Case IV: Two Negative Numbers:- Consider the addition of -5 and -9:
Note:- The final carry bit is discarded.
The sum is negative and therefore in
2's complement form.
In a computer, the negative numbers are stored in 2's complement form so. as you
can see, the addition process is very simple: Add the two numbers and discard any
final carry bit.
Overflow Condition:- When two numbers are added and the number of bits required
to represent the sum exceeds the number of bits in the two numbers, an overflow
results.
An overflow can occur only when both
numbers are positive or both numbers are
negative.
24
Cont.…
B) SUBTRACTION
Subtraction is a special case of addition.
For example, subtracting +6 from +9 is equivalent to adding -6 to +9.
Basically, the subtraction operation changes the sign of the subtrahend and adds it
to the minuend.
The result of a subtraction is called the difference.
NOTE:-The sign of a positive or negative binary number is changed by taking its 2's
complement.
To subtract two signed numbers, take the 2's complement of the subtrahend and
add. Discard any final carry bit.
25
HEXADECIMAL NUMBERS
The hexadecimal number system has a base of sixteen; that is, it is composed of 16
numeric and alphabetic characters.
The hexadecimal number system consists of digits 0,1,2…9 and letters A,B,C,D,E & F
Binary-to-Hexadecimal Conversion
Simply break the binary number into 4-bit groups, starting at the LSB and replace
each 4-bit group with the equivalent hexadecimal symbol.
Hexadecimal-to-Binary Conversion
To convert from a hexadecimal number to a binary number, reverse the process and
replace each hexadecimal symbol with the appropriate four bits.
Hexadecimal is a convenient way to represent binary numbers. 26
Cont.…
Hexadecimal-to-Decimal Conversion
One way to find the decimal equivalent of a hexadecimal number is to first convert
the hexadecimal number to binary and then convert from binary to decimal.
Exapmle:- Convert the following hexadecimal numbers to decimal:
Another is to multiply the decimal value of each hexadecimal digit by its weight and
then take the sum of these products.
Example:-Convert the following hexadecimal numbers to decimal:
27
Hexadecimal Addition
Addition can be done directly with hexadecimal numbers as the following example
Example:- Add the following hexadecimal numbers:
Hexadecimal Subtraction
Convert the hexadecimal number to binary. Take the 2's complement of the binary
number. Convert the result to hexadecimal.
Example:- Subtract the following hexadecimal numbers:
To convert an octal number to a binary number, simply replace each octal digit with
the appropriate three bits.
Example:-Convert each of the following octal numbers to binary:
29
Binary-to-Octal Conversion
Conversion of a binary number to an octal number is the reverse of the octaJ-to-
binary conversion.
Start with the right-most group of three bits and, moving from right to left, convel1
each 3-bit group to the equivalent octal digit.
Example:-Convert each of the following binary numbers to octal:
30
BINARY CODED DECIMAL (BCD)
Binary coded decimal means that each decimal digit, 0 through 9, is represented by
a binary code of four bits.
The 8421 code is a type of BCD (binary coded decimal) code.
The designation 8421 indicates the binary weights uf the four bits (2 3 , 22 , 21 ,20 )
Invalid Codes:-The six code combinations that are not used-1010, 1011, 1100, 1101,
1110, and 1111-are invalid in the 842] BCD code..
To express any decimal number in BCD, simply replace each decimal digit with the
appropriate 4-bit code, as shown by Example:
Example:-Convert each of the following decimal numbers to BCD:
31
Cont.…
It is equally easy to determine a decimal number from a BCD number.
Start at the right most bit and break the code into groups of four bits.
Then write the decimal digit represented by each 4-bit group.
Example:-Convert each of the following BCD codes to decimal:
32
DIGITAL CODES
Many specialized codes are used in digital systems.
You have just learned about the BCD code; now let's look at a few others.
Some codes are strictly numeric, like BCD, and others are alphanumeric; that is, they
are used to represent numbers, letters, symbols, and instructions.
The codes introduced in this section are the Gray code and the ASCII code.
The Gray Code
The Gray code is unweighted and is not an arithmetic code; that is, there are no
specific weights assigned to the bit positions.
The important feature of the Gray code is that it exhibits only a single bit change
from one code word to the next in sequence.
This property is important in many applications, such as shaft position encoders,
where error susceptibility increases with the number of bit changes between
adjacent numbers in a sequence.
Like binary numbers. the Gray code can have any number of bits. Notice the single-
bit change between successive Gray code words.
33
Cont.…
The following table is listing of the 4-bit Gray code for decimal numbers 0,1,2,…15.
Example3:
38
Exercise
39