The document discusses computer logic and arithmetic operations in binary. It begins by defining number systems and explaining that computers use binary. It then covers:
- Adding and subtracting binary numbers by applying set rules.
- Representing numbers using signed, one's complement, two's complement and modified codes to simplify arithmetic operations.
- How addition and subtraction are performed on binary numbers represented in these codes, including how overflow is detected.
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Computer arithmetic operations.pptx
1. COMPUTER LOGIC
PART 1
LOGIC OF COMPUTER ARITHMETIC OPERATIONS
ACCORDING TO
Матвієнко М.П. Комп’ютерна логіка. Навчальний посібник.—
K.: Видавництво Лipa-K, 2012. — 288 с.
ISBN 966-2609-09- 7
2. AGENDA
What Logic is
Number Systems
Arithmetic operations over binary numbers
Number representation by signed, one’s, two’s
compliment and modified codes
The logic of adding and subtracting binary numbers
3. 1.1. Number Systems
• Definition 1.1.1. A number system is a system of displaying any numbers
using a limited number of digits.
Depending on the ways of displaying numbers with digits, number systems
are divided into positional and non-positional.
• Definition 1.1.2. A non-positional number system is a system in which the
quantitative value of each digit does not depend on the place in the display of
the number, but is determined only by the number symbol itself. So, for
example, the number 30 of the decimal numbering system in the Roman non-
positional system is denoted as the number XXX, which has the same symbol
X in all digits, which means 10 units, regardless of its position in the display of
the number.
• Definition 1.1.3. A positional numbering system is a system in which the
quantitative value of each digit depends on its place in the display of the
number.
• Definition 1.1.4. The number of digit used to display a number in the
positional numbering system is called the basis of the numbering system .
4. 1.1. Number Systems
• Any number that satisfies the condition d>2 is the basis of the counting system d.
In the binary numbering system d = 2 and to represent numbers you use symbols (1, 0),
in octal d = 8 and to represent numbers you use symbols (0, 1, 2, 3, 4, 5, 6, 7), and in
hexadecimal, d = 16, and for the representation of numbers, the symbols are (0, 1, 2, 3,
4, 5, 6, 7, 8, 9, A, B, C, DI, E, P), where A = 10 ; B = 11; C= 12; D= 13; E= 14: F= 15.
• The binary number system is the main number system in which arithmetic and logical
operations are performed in computers, because two-position electronic elements are
widely used for its technical implementation.
• The conversion of numbers from the decimal numbering system to binary, octal and
hexadecimal and vice versa is of significant importance when performing arithmetic and
logical operations in computers. To convert whole numbers, the algorithm of dividing a
given number by the basis of the number, into whose system it is converted, is most
often used.
5. 1.1. Number Systems
The algorithm has the following steps:
1. Divide the number to be translated in the number system with the base d into the base
p according to the rule of the number system with the base d.
2. Check whether the remain is not equal to zero. If it is not equal, then take it as a new
number and return to step 1.
3. If the remain is equal zero, then write out all the obtained remainders from the division
in the reverse order of their receipt.
4. The resulting entry is the entry of a number in the number system with the base p.
Example. Convert the number 13(10) from the decimal system to binary
13(10) = 1101(2)
1*23+1*22+0*21+1*20
6. 1.1. Number Systems
To convert fractional numbers, use the algorithm of multiplying a given number by
the base of the number into which it will be converted. This algorithm has the following
steps.
1. Multiply the fractional number with the base q by the base of the number system p,
into which it is converted.
2. In each result, select integer parts, if any.
3. The highlighted whole parts of the product and are the digits of the fractional part of the
number.
Example. Convert the number 0.45 (10) from the decimal number system to binary with an
accuracy of 10-4 and check the solution.
The solution. According to the algorithm for converting fractional numbers, we
successively multiply the fractional number 0.45 of the decimal numbering system by the
base of the binary numbering system four times, as a result of which we get
0,45 0,90 0,80 0,60
x x x x
2 2 2 2
------- ------- -------- ---------
0,90 1,80 1,60 1,20 45(10) = 0,0111(2)
7. 1.2. Arithmetic operations over binary numbers
Four arithmetic operations to the binary counting system (addition,
subtraction, multiplication and division) are considered.
Addition. When adding binary numbers, you must use the following rules
a) 0 + 0 = 0; b) 0+1=1; c) 1+0=11; d) 1+ 1= 10 (1.2.1)
A two-digit sum of addition in d) means that when adding binary digits that are equal to 1,
there is a transfer of 1 to the next higher digit. This carry must be added to the sum of the
digits that are formed in the adjacent digit on the left.
Example. Add two binary numbers A1 = 1101101 and A2= 1001111.
The solution: accordance with 1.2.1, we perform bit-by-bit addition binary numbers A1
and A2
8. 1.2. Arithmetic operations over binary numbers
Substruction. When subsruction binary numbers, you must use the following
rules
a) 0 - 0 = 0; b) 1 – 0 =1; c) 1 – 1 =0; d) 10 – 1 = 1 (1.2.2)
In addition, it is necessary to remember that
1000...0 - 1 = 111..1 . (1.2.3)
n zeros
Example. Substruction two binary numbers A1 = 11000011 and A2= 10100111.
There was no need use borrow for lower two bits.
For the third bit, it is made borrow from the seventh digit (closest non-zero bit).
In the intermediate bit, the subtraction takes place from one (1.2.3).
9. 1.2. Arithmetic operations over binary numbers
Multiplication. Multiplying two binary numbers is done in the same way as
multiplying two decimal numbers. That is, the product is successively multiplied by
each digit of the multiplier, starting with the youngest or the oldest. To take into account
the weight of the corresponding digit of the factor, the result moves either to the left, if the
multiplication occurs starting from the lowest digit of the factor, or to the right, if the
multiplication occurs starting from the highest digit of the factor. At the same time, the
movement takes place on the corresponding number of digits the digit of the multiplier is
shifted relative to its lower or higher digit. Obtained as a result of multiplication and shift
partial products after addition give the full result of multiplication.
Example Multiply two binary numbers A1 = 10101 and A2 = 1011 shift left and right.
The solution. In accordance with the we will have:
Shift left Shift right
10. 1.2. Arithmetic operations over binary numbers
Division. Division of binary numbers is similar to division of decimal numbers in
many ways. In computers, as a rule, the "school" algorithm for dividing numbers is
implemented. The "school" division algorithm consists in the fact that the divisor at each
step is subtracted from the divided as many times (starting with the highest digits) as
possible to obtain the smallest positive remainder. Then, a number equal to the number
of divisors contained in the dividend at this step is written in the next digit of the quotient.
In other words, during division, the subtraction operation is repeated until the thing being
reduced becomes less than what is being subtracted. The number of these repetitions
shows how many times the denominator is placed in the decrement.
Example. Perform division of two binary numbers A1 = = 110111 and A2 = 10010 under
the condition that in one case the divisor is A1 and a divisor of A 2, and in the other - vice
versa
11. 1.3. Number representation by signed, one’s, two’s
compliment and modified codes
Arithmetic operations in computers performing using numbers encoded with special
machine codes. There are several types of such codes - signed, one’s compliment , two’s
compliment and modified codes which allow you to replace the subtraction operation with the
addition operation, which simplifies the arithmetic logic device of the computer. Signed code is
based on representing numbers in their form absolute value with plus or minus sign code.
Signed code (прямий код) is based on representing numbers in their form absolute value
with plus or minus sign. The formula for finding the signed code of the binary number
most significant bit, MSb least significant bit, LSb (0 has two different representation)
12. 1.3. Number representation by signed, one’s, two’s
compliment and modified codes
Two’s compliment (обернений/зворотній) code. Formula for displaying two’s compliment
code binary number A has the for:
According tj the formula one’s compliment of the positive number is coincides with one’s
compliment of the positive code. One’s compliment of the negative have 1 in the sign digit,
and in all numerical digits in rows, zeros must be replaced by ones, and ones - by zeros.
There is no negative zero in the additional code.
There is no negative zero in the one’s compliment code.
13. 1.3. Number representation by signed, one’s, two’s
compliment and modified codes
One’s compliment (додатковий) code. Formula for displaying one’s compliment code
binary number A has the for:
According tj the formula one’s compliment of the positive number is coincides with one’s
compliment of the positive code. One’s compliment of the negative have 1 in the sign digit,
and in all numerical digits in rows, zeros must be replaced by ones, and ones - by zeros and
1 must be added to the lower.
There is negative zero in the one’s compliment code.
14. 1.3. Number representation by signed, one’s, two’s
compliment and modified codes
Modified codes. These codes are used for detection bit grid overflow that can occur when
adding binary numbers. Modified codes are different from simple ones machine codes by the
fact that they are assigned to display the sign in them two categories. A plus is represented by
two zeros, and a minus by two ones.
15. 1.4. The logic of adding and subtracting binary numbers
Adding fixed-point numbers in a modified two’s compliment code makes according to the
rules of binary arithmetic. A carry that occurs in the most significant bit is rejected. The sign
digit of the number is the second from the left from the decimal point, and the first one is used
for overflow analysis bit grid.
Example. Add the binary numbers A1 and A2 represented in the modified two's complement
code where:
16. 1.4. The logic of adding and subtracting binary numbers
Adding fixed-point numbers in a modified one’s compliment code is performed same as in
the two’s compliment code. is performed as in the additional code. Difference consists only in
the fact that the carrier from the higher sign bit (if it exist) must be added to the lower bit of the
sum.
Example. Add the binary numbers A1 and A2 represented in the modified one's complement
code where:
17. 1.4. The logic of adding and subtracting binary numbers
Overflow when adding in modified codes are detected by comparing sign bit of the sum.