Week 2
Week 2
Based on the type of signal that the system handles, there are two types of
systems: analog and digital. Analog systems process analog signals; for
example, volume control on old radios, telephone handsets, and TR-10
desktop analog computers. Since analog signals involve continuous signals, it
requires huge memory to store the collected information. Also, designed
systems cannot be easily modified in real-time.
Digital systems process digital signals in the form of discrete signals, which
are obtained by sampling analog signals. The process of converting analog
signal to digital signal is shown in Figure 1. A signal sampler is a kind of
high-speed switch that takes an analog signal as an input and produces
discrete signals at predefined time intervals. Such signals have a finite set of
possible amplitudes. The best example of a digital system is a computer that
uses digital signals in the form of square waves. This kind of digital signal has
only two amplitudes or voltage levels, namely high voltage level and low
voltage level.
Since digital signals are obtained by sampling analog signals, the accuracy of
the digital signal obtained depends on the sampling rate. If the sampling rate
is low, sampled information will be irreversibly lost, and the original signal will
not be represented correctly. A higher sampling rate provides better accuracy
but will have an impact on storage capability and the amount of time it takes to
process the information. There is always a compromise between sampling
rate, processing time, and storage.
Since digital systems are more reliable, they are employed in almost all
applications, including computer systems.
In binary, bi means 2. The binary number system uses only two symbols or
digits 0 and 1. Since there are two distinct symbols, the base of the binary
number system is 2. In the octal number system, oct means 8. Base of the
octal number system is 8 and uses eight symbols 0 to 7. In the decimal
number system, deci means 10. The base of the decimal number system is 10
and uses ten symbols from 0 to 9. Hex in a hexadecimal number system
means 6, and deci means 10. The hexadecimal number system uses a base
value of 16 and uses 16 distinct symbols to represent a number. It uses 0 to 9
and A to F symbols.
The decimal number system has a base value of 10 and uses ten symbols
from 0 to 9. Consider 1248.84 as an example. As shown in Figure 6, this
number has two parts, that is, the integer part and the fractional part, and they
are separated by a decimal point.
Figure 6: Example of decimal number representation.
The main advantages of the decimal number system are that they are easy to
represent, read, and manipulate. Hence, it is most used in daily life. However,
decimal number representation cannot be employed in computers for the
following reasons:
● Hard to store:
This is because each digit in a number is made of ten symbols. The first
electronic computer ENIAC used ten vacuum tubes per digit, and the
computer design was very bulky.
● Hard to transmit:
Encoding ten different symbols requires ten signal levels so that it can be
transmitted over a single wire. Also, to minimize the errors, high-precision
encoding is needed.
The binary number system uses only two possible values, 0 or 1, for each
digit in a number. This number system is used in every digital system because
of easy storage, easy transmission, and easy implementation of required
functions. In such systems, everything is represented by either the presence
or absence of a signal. The presence of a signal is usually interpreted as digit
1, and the absence of a signal as digit 0.
Each digit in a binary number is known as a bit. The binary number is made
up of several bits. The rightmost bit is known as the least significant bit, LSB,
whereas the leftmost bit is known as the most significant bit, MSB. In a digital
system, MSB is the bit that has the largest weight in a binary number,
whereas LSB has the least weight. Figure 8 shows the position of MSB and
LSB for two example binary numbers.
Figure 8: Position of MSB and LSB.
Since a binary number system is a positional number system, each bit has a
positional value and weight associated with it. Figure 9 shows the example
binary number 11010.11, which has integer and fractional parts. Before the
decimal point, that is the integer part, the bits are represented as b0, b1, b2,
b3, and b4, and the corresponding weight is 20, 21, 22 23 and 24. After the
decimal point, bits are represented as b-1, b-2, etc.; and their corresponding
weight is 2-1, 2-2, etc.
While converting from decimal to binary, integer and fractional parts are
converted separately. For converting the integer part to binary, the successive
division method is used, whereas for converting the fractional part, successive
multiplication is used. For both division and multiplication, the target number
system’s base, which is base 2, is considered. In general, while converting the
integer part, first divide the integer part of the decimal number by 2. The first
remainder that is obtained will be the LSB of the binary number. If the quotient
is zero, the conversion is complete. If the quotient is not zero, then the
quotient will be divided by 2. The new remainder is the next most significant
bit of the binary number. This continues until the quotient becomes 0.
For fractional part conversion, multiply the fractional part by 2. The carry
generated is kept aside, and the fraction will then be multiplied by 2. This
process is continued until the fractional part is zero or the required accuracy is
attained. Figure 10 shows the decimal number 125.66 to binary conversion.
Bit Permutation
In general, in any number system, the total numbers that are represented
depend on the number of digits in that number. In a binary number system, if a
number sequence has n bits, then we can have 2n possible combinations or
permutations; for example, if n = 1, then there are two combinations, that is, 0
and 1. Similarly, when n = 2, there will be four combinations, 00, 01, 10, and
11. Figure 12 shows the permutation table for n = 1, 2, and 3.
Figure 12: Permutation table for n = 1, 2, and 3.
● Method 1: First, convert the binary number to decimal number and then
to octal number.
Octal to Binary:
Bitwise Addition
A logic circuit is an essential building block of a logic system that will have
several inputs and outputs. In any logic system design, the truth table plays an
important role. The truth table lists all possible combinations of input binary
variables and the corresponding outputs of a logic system. When the number
of input binary variables is one, there are only two possible input
combinations: "0” and “1.” If the number of inputs is two, there can be four
possible input combinations, that is, 00, 01, 10, and 11. Similarly, the number
of possible input combinations for three input binary variables becomes eight.
So, if a logic circuit has n binary inputs, its truth table will have 2n possible
input combinations.
Consider two inputs A and B. There are two outputs, Sum and Carry. Figure
20 shows the truth table consisting of inputs and outputs. Since there are two
inputs, there are four possible combinations.
● When A = 0 and B =0, adding 0 with 0 yields the sum as zero, with no
carry, which is indicated as zero in the truth table.
● When A = 0 and B =1, adding 0 with 1 yields the sum as 1, with no
carry.
● When A = 1and B = 0, adding 1 with 0 yields the sum as 1, carry as 0.
● When A = 1 and B = 1, adding 1 with 1 will result in 0 and carry 1.
1’s Complement
In 1’s complement operation, we flip or invert all the bits in a number; that is,
change 0 to 1 and 1 to 0. For example, 1’s complement of 1100 is 0011.
2’s Complement
Figure 4: 3-bit binary representation using signed magnitude and 1’s complement representation.
For the n-bit number, the number of positive numbers is 2n- 1-1, the number of negative numbers is
2n- 1-1, and there are two representations for 0. The range of numbers that can be represented is
given by -2n- 1-1 to +2n- 1-1.
2.2.4 Addition of 1’s Complement Numbers
Four cases of 1’s complement number addition are evaluated to check the suitability of 1’s
complement representation for digital computers. While representing the numbers, the table in
Figure 4 is referred to.
Case 1: Perform 1 + 2
+1 🡺 0 0 1
+2 🡺 0 1 0
+3 0 1 1
+3 in binary is 011, which matches the answer obtained after the binary addition. Hence, the addition
operation is correct.
Case 2: Perform 2 + (-3)
+2 🡺 0 1 0
-3 🡺 1 0 0
-1 1 1 0
When +2 and -3 are added, the result obtained is -1. The result of binary addition is 110, which is
also equal to -1. Hence, the addition operation is correct.
Case 3: Perform 3 + (-3)
+3 🡺 0 1 1
-3 🡺 1 0 0
0111
When decimal addition of +3 and -3 is performed, the result obtained is 0, which can be represented
as either +0 or 0. The result obtained after adding binary numbers is 111, which is equal to -0.
Hence, the addition operation is correct.
Case 4: Perform 3 + (-2)
+3 🡺 0 1 1
-2 🡺 1 0 1
11000
Ignoring the carry results in 000, which is equal to +0. But when +3-2 is performed, the result
obtained is 1, which does not match the result obtained after binary addition. Hence, the addition
operation is incorrect. But there is a way to correct this, that is, adding carry to the result obtained.
After adding carry, the result will be 001, which matches the result of decimal addition.
The main advantage of 1’s complement representation is that it can be used for arithmetic
operations. But whenever there is a final carry generated out of MSB, it needs to be added to the
number. The disadvantage is that the representation is not very easy to understand. When there is a
carry, it needs to be handled properly to get the right answer.
2.2.5 2’s Complement Representation
2’s complement representation is used to represent both positive and negative numbers. While
representing the positive number, convert the given number to a binary number. Hence, positive
number representation is the same for signed magnitude representation, 1’s complement
representation, and 2’s complement representation. For negative number representation, take the
magnitude of the number and convert it into binary, and then apply 2’s complement operation on the
number.
For example, to represent -15 using 8 bits, the following steps are followed.
Step 1: Take the magnitude of -15. The magnitude of -15 is+ 15 and then convert + 15 into binary.
+ 15🡺 0 0 0 0 1 1 1 1
Step 2: Find 1’s complement of binary and add 1 to it.
Figure 5 shows the 3-bit binary representation using signed magnitude, 1’s complement
representation, and 2’s complement representation. It can be observed that the 2’s complementation
has one representation for 0. Positive number representation is the same as that of other
representations. There are four negative numbers. The combination 100, which represents -4, is
called a weird number. It is called a weird number because inverting 100 and adding 1 to it results in
100 itself. Hence, this negative number has no positive counterpart. But for all other negative
numbers, there is a positive counterpart.
Figure 5: 3-bit binary number representation using signed magnitude, 1’s complement
representation, and 2’s complement representation.
2.2.6 Addition of 2’s Complement Numbers
Four cases of 2’s complement number addition are evaluated to check the suitability of 2’s
complement representation for digital computers. While representing the numbers, the table in
Figure 5 is referred to.
Case 1: Perform 1 + 2
+1 🡺 0 0 1
+2 🡺 0 1 0
+3 0 1 1
+3 in binary is 011, which matches the answer obtained after the binary addition. Hence, the addition
operation is correct.
Case 2: Perform 2 + (-3)
+2 🡺 0 1 0
-3 🡺 1 0 1
-1 1 1 1
When +2 and -3 are added, the result obtained is -1. The result of binary addition is 111, which is
also equal to -1. Hence, the addition operation is correct.
Case 3: Perform 3 + (-3)
+3 🡺 0 1 1
-3 🡺 1 0 1
01000
When the decimal addition of +3 and -3 is performed, the result obtained is 0, which can be
represented as either +0 or 0. The result obtained after adding binary numbers is 1000. Ignoring the
carry, we obtain 000, which is equal to +0. Hence, the addition operation is correct.
Case 4: Perform 3 + (-2)
+3 🡺 0 1 1
-2 🡺 1 1 0
11001
When the decimal addition of +3 and -2 is performed, the result obtained is 1. Ignoring the carry
results in 001, which is equal to +1. Hence, the addition operation is correct.
All these four cases show that 2’s complement representation is suitable for digital computers.
Operation on Bits
The decimal equivalent of 0000 1001(2) is +9. When two positive numbers are added, the result
should always be positive.
Case 2: A - B
A - B 🡺 A + (-B)
🡺+ 5 in 8-bit representation = 0 0 0 0 0 1 0 1
🡺- 4 in 8-bit representation
🡺A +(-B )
Ignore carry. The decimal equivalent of 00000001(2) is +1. Since A is greater than B, the result
should be positive.
Case 3: -A + B
🡺- 5 in 8-bit representation
🡺+ 4 in 8-bit representation:0 0 0 0 0 1 0 0
🡺-A + B
The decimal equivalent of 1 1 1 1 1 1 1 1(2) is -1. The magnitude of -5 is 5, which is more than 4.
Hence, the result will have a sign of 5, which is negative in this case.
Case 4: -A - B
-A - B 🡺 - A + (-B)
🡺 - 5 in 8-bit representation = 1 1 1 1 1 0 1 1
🡺 - 4 in 8-bit representation = 1 1 1 1 1 1 0 0
🡺 -A + (-B)
Ignore carry. The decimal equivalent of 1 1 1 1 0 1 1 1(2) is -9. Since -5 and -4 are negative
numbers, the result will also have a negative sign.
2.3.2. Arithmetic Operation: Sign Extension and Overflow
Sign extension, short known as sext, is the operation in the computer system. Using sign extension,
number of bits of the binary number is increased while preserving the value of the number. While
adding two binary numbers, care must be taken to ensure that two numbers’ sign bits are aligned.
Failing which may result in erroneous results.
The process of sign extension is illustrated in Figure 2. The original number 1 0 0 0 1 has five bits.
This number needs to be extended to eight bits. Five bits of the original number are copied as it is,
and the remaining three bits are filled with the sign of the number. The new number is the
sign-extended version of the original number.
Figure 2: Process of sign extension.
Another issue in computer arithmetic is the overflow condition. Consider two numbers A = +10 and B
= +8. These two numbers are represented using 5-bit 2’s complement representation. Adding these
two numbers will result in the following.
The result obtained is -14 instead of +18. The main reason behind this is that it is unable to
accommodate +18 using five bits. The range of numbers that can be represented using five bits is
-16 to +15. Hence, the result has overflowed the capacity of the representation.
When two 2’s complement numbers are added, and they both have the same sign (both positive or
both negative), then overflow occurs if and only if the result has the opposite sign. In almost all
programming languages, overflow is considered an exception that needs to be handled properly.
2.3.3 Logical Operation: AND, OR, NOT, NAND, NOR, EXOR, and EXNOR
A logic gate is an electronic circuit that acts as a building block for all digital circuits. These circuits
perform logical operations. There are three basic logic gates, namely the OR gate, the AND gate,
and the NOT gate. These basic logic gates are used to implement the most elementary logic
expressions. Other logic gates that are derived from these basic gates are the NAND gate, the NOR
gate, the EXCLUSIVE-OR gate, and the EXCLUSIVE-NOR gate.
AND Gate: AND operation is performed by AND gate with two or more inputs and one output. The
symbol of the AND gate with two inputs, A and B, and output Y, and the truth table is shown in Figure
3. The output of an AND gate is 1 only when all its inputs are in the 1 state. For all other input
combinations, the output is 0. The logic expression is given by
Y = A AND B
= A·B
= AB