COA Assignment
COA Assignment
Submitted to:-
ABRHAM.D(Assistant prof)
1
1.introduction............................2
2.signed and unsigned
addition of binary numbers ........... ....3
2.1 addition of signed
binarynumber ................................ ..3
2.2 representation of signed addition binary
numbers ........................ ...4
2.3 unsigned addition of
binary numbers.............................. ... .......8
2
substraction
4.0 multiplication of signed and unsigned ...........16
binary numbers
4.1multiplication of unsigned ................. 16
binary numbers
4.2 multiplication of signed ........... 18
binary numbers
5.0 division of signed and unsigned ...............19
binary numbers
5.2 division of signed ........ ... 20
binary numbers
6.0 floating point representation of ............23
signed and unsigned binary numbers
Introduction
Binary arithmetic is the mathematical operation performed on binary numbers, which are
composed of only two digits: 0 and 1. This system is the foundation of all computing
processes, as computers operate using binary logic. Understanding how to manipulate binary
numbers is essential for software development, digital electronics, and computer
engineering.Unsigned binary numbers represent non-negative integers. The leftmost bit
3
(most significant bit) indicates the highest value, while the rightmost bit (least significant bit)
represents the lowest values.
Binary division is akin to long division in decimal. For instance, dividing 1010 (10 in decimal)
by 10 (2 in decimal) results in:
Signed binary numbers can represent both positive and negative integers. The most common
method for representing signed numbers is the Two's Complement method. In this format,
the leftmost bit indicates the sign: 0 for positive and 1 for negative.
When adding signed numbers, if both operands have the same sign and the result has a
different sign, an overflow has occurred.
The multiplication of signed binary numbers also follows similar rules as unsigned
multiplication but requires attention to the signs. If the signs of the operands differ, the result
is negative.Division follows similar principles as multiplication. The sign of the result depends
on the signs of the operands. If they differ, the result is negative.
4
Signed Addition of binary numbers
• Signed Binary Number: A binary number of fixed length whose sign (+/-) is
represented by one bit (usually MSB) and its magnitude by the remaining bits.
• Unsigned Binary Number: A binary number of fixed length whose sign is not
specified by a bit. All bits are magnitude and the sign is assumed +.
• Sign Bit: A bit (usually the MSB) that indicates whether a number is
positive(=0) or negative (=1).
• Magnitude Bits: The bits of a signed binary number that tell how large it is in
value.
• True Magnitude Form: A form of signed binary whose magnitude bits are the
TRUE binary form (not complements)5
(1) If the signs are the same, add the magnitudes and use that same sign for the
result; (2) If the signs differ, you must determine which operand has the larger
magnitude.
5
Representation of Signed Binary Numbers
1. Two's Complement: The most common method for representing signed
binary numbers is the two's complement system. In this system:
Example
- Binary of 5: 00000101
- To represent -5:
When adding signed binary numbers using two's complement, follow these
steps:
1. Align the Numbers: Write the numbers to be added one above the other,
ensuring they are aligned correctly by their least significant bits.
2. Perform Binary Addition: Add the numbers just like regular binary addition,
carrying over any overflow as needed.
- Overflow occurs if the sign of the result is incorrect based on the signs of the
operands.
- For example, if you add two positive numbers and get a negative result, or if
you add two negative numbers and get a positive result.
6
Example of Signed Binary Addition
- +5: 00000101
- -3:
- Binary of 3: 00000011
- Invert: 11111100
00000101 (+5)
+ 11111101 (-3)
______________
00000101
+ 11111101
______________
00000010 (Result)
7
• Case 2: Two Postive Numbers.
0 1001(+9)
+ 00100(+4)
10111(-9)
+ 00100(+4)
10111(-9)
8
+11100(-4)
110011 (result)
In this case, both operands were negative and the result is negative
respectively, so overflow is not a concern. If we had added two large positive
numbers and obtained a negative result, we would have an overflow.
- The leftmost bit (most significant bit, MSB) contributes the highest value.
- 00000000 represents 0.
- 00000001 represents 1.
- 00000010 represents 2.
The addition of unsigned binary numbers is similar to decimal addition. You add
corresponding bits starting from the LSB, carrying over any overflow to the next
higher bit.
9
Steps for addition of unsigned binary numbers
1. Align the Numbers: Write the numbers to be added one above the other,
ensuring they are aligned by their least significant bits.
2. Perform Binary Addition: Add the bits column by column, from right to left,
carrying over any overflow as needed.
+ 0101 (5 in decimal)
_________
- Since there are no more bits to add, write down the carry.
10
Carry: 1111
1011
+ 0101
_________
10000
• Result Interpretation:
In this case, if we were working with only a 4-bit representation, we would only
keep the last four bits of the result:
- The final result would be 0000, indicating that we have overflowed beyond
what can be represented in a 4-bit unsigned number.
(minuend), take the twos complement (negation) of the subtrahend and add it
to the minuend.
11
1. Two's Complement: This is the most widely used method for representing
signed integers in binary. In this system:
- The leftmost bit (most significant bit) indicates the sign: 0 for positive and 1
for negative.
- To find the two's complement of a number, invert all bits and add 1.
To subtract a signed binary number using two's complement, follow these steps:
2. Add the Minuend and the Two's Complement of the Subtrahend: Perform
binary addition.
- 3 in two's complement:
12
- Add (1): 1100 + 0001 = 1101. So, (-3) is 1101.
- 5 in binary:
- Add (1): 1010 + 0001 = 1011. So, (5) in two's complement is 1011.
Carry: 111
1101 (-3)
+ 1011 (-5)
_________
11000
The result is 11000. Since we are using 4 bits, we only keep the last four bits,
which gives us 1000.
13
- Add (1): 0111 + 0001 = 1000. So, 1000 represents (-8).
then substract from the minued.first find the twos complemt of -4 then add.the
twos complemt of -4 is 0100.
1010
+ 0100
1110
Check: it start by 1 then the number is negative.add the left three one bit.
-8+4+2=-2.
We know that subtraction is the same as “adding the opposite,” which equates to
negating the value we wish to subtract and then adding instead (which is often
much easier than performing all the borrows necessary for subtraction,
particularly in dealing with binary numbers).
14
1.If the signs are the same, add the magnitudes and use that same sign for the
result.
2.If the signs differ, you must determine which operand has the larger magnitude.
The sign of the result is the same as the sign of the operand the larger magnitude,
and the magnitude must be obtained by subtracting (not adding) the smaller one
from the larger one.
- represent 12 in binary:
- 5 in binary:
-1100 (12)
- 0101 (5)
15
- Bit 0: (0 - 1) → Borrow from next column. Current column becomes (10 - 1 = 1).
- Bit 2: After borrowing, we have (0 - 1) → Borrow from next column again. This
column becomes (10 - 1 = 1).
1100
- 0101
--------
0111
Example 2
1001111(79)
- 1100011(99)
16
negative numbers.the simplest multiplication algorithms used by computers are
similar to traditional pencil-and-paper methods used by humans. The complete
multiplication table for binary numbers couldn’t be simpler: zero times any
number is zero, and one times any number is that number.
1. Multiplication involves the generation of partial products, one for each digit in
the multiplier. These partial products are then summed to produce the final
product.
2.The partial products are easily defined. When the multiplier bit is 0, the partial
product is 0. When the multiplier is 1, the partial product is the multiplicand.
3. The total product is produced by summing the partial products. For this
operation, each successive partial product is shifted one position to the left
relative to the preceding partial product.
17
4. The multiplication of two n-bit binary integers results in a product of up to 2n
bits in length (e.g., 11 * 11 = 1001).
1011
❌ 1101
1011
0000X
1 0 1 1X X
1 0 1 1 XXX
Finally add
result=10001111
Multiplicand (11)
Multiplier (13)
Product (143)
Compared with the pencil-and-paper approach, there are several things we can
do to make computerized multiplication more efficient.
First, we can perform a running addition on the partial products rather than
waiting until the end. This eliminates the need for storage of all the partial
products; fewer registers are needed.
Second, we can save some time on the generation of partial products. For each 1
on the multiplier, an add and a shift operation are required; but for each 0, only a
shift is required.
18
Multiplication of signed binary number allows the multiplication both negative
and positive numbers.
So far, we have dealt with positive numbers. Th e easiest way to understand how
to deal with signed numbers is to fi rst convert the multiplier and multiplicand to
positive numbers and then remember the original signs. Th e algorithms should
then be run for 31 iterations, leaving the signs out of the calculation. As we
learned in grammar school, we need negate the product only if the original signs
disagree.It turns out that the last algorithm will work for signed numbers,
provided that we remember that we are dealing with numbers that have infi nite
digits, and we are only representing them with 32 bits. Hence, the shift ing steps
would need to extend the sign of the product for signed numbers. When the
algorithm completes, the lower word would have the 32-bit product.
Example
numbers.
1101
❌ 0101
00000011
11111101
00000011
19
11111101
•Divide’s two operands, called the dividend and divisor, and the result, called the quotient, are
accompanied by a second result, called the remainder. Here is another way to express the
relationship between the components:
where the remainder is smaller than the divisor. Infrequently, programs use the divide
instruction just to get the remainder, ignoring the quotient.
Th e basic grammar school division algorithm tries to see how big a number
can be subtracted, creating a digit of the quotient on each attempt. Our carefully
selected decimal example uses only the numbers 0 and 1, so it’s easy to fi gure out
how many times the divisor goes into the portion of the dividend: it’s either 0 times or 1 time.
Binary numbers contain only 0 or 1, so binary division is restricted to
Let’s assume that both the dividend and the divisor are positive and hence the
quotient and the remainder are nonnegative. Th e division operands and both
results are 32-bit values, and we will ignore the sign for now.
20
Examples of signed binary number division
Divide the value –14 (expressed using 8-bit signed two’s complement
representation) by 2.
11110010
and we shift right one place (carrying across the sign bit), resulting in:
11111001
21
21
Examples of unsigned binary number division
Example Consider the division of a dividend X = 32 = (0100000)
and a divisor D=6=(0110).
2r0 0 1 0 0 0 0 0
-D + 1 1 0 1 0
r1 =2r0 -D 00 0 1 000
2r1. 0 0 10 0 0 Set q2 =0
r2 =2r1 0 010 0 0
-D + 11010
r3 = 2r2 - D 00010
22
2r3 0010 Set q4 = 023
The resultant quotient is Q =0101 = (5) and the remainder R ¼=0010 (2). These are
correct values.23
00001100
and we shift right one place, copying the sign bit of 0, resulting in:
00000110
23
• Scientific notation simplifies pencil and-paper calculations that involve very large or very small
numbers. It is also the basis for floating-point computation in today’s digital computers.24
size of the fraction and the size of the exponent, because a fixed word size means
you must take a bit from one to add a bit to the other. Th is tradeoff is between
precision and range: increasing the size of the fraction enhances the precision of the fraction,
while increasing the size of the exponent increases the range of numbers that can be
represented.
•This representation is essential in computing for handling a wide range of values, including
very small and very large numbers.
* Exponent (E): Determines the scale or magnitude of the number. It is usually stored in a
biased format.
*. Mantissa (or Significand) (M): Represents the significant digits of the number.
+S ×B^ +E
24
• Sign: plus or minus
• Significand S
• Exponent E
For decimal numbers, we get around this limitation by using scientific notation. Thus,
976,000,000,000,000 can be represented as 9.76 * 1014, and 0.0000000000000976 can be
represented as 9.76 * 10-14. What we have done, in effect, is dynamically to slide the decimal
point to a convenient location and use the exponent of 10 to keep track of that decimal point.
This allows a range of very large and very small numbers to be represented with only a few
digits.
The most widely used standard for floating-point representation is IEEE 754.
adopted in 1985 and revised in 2008. This standard was developed to facilitate the
portability of programs from one processor to another and to encourage the development of
sophisticated, numerically oriented programs. The standard has been widely adopted and is
used on virtually all contemporary processors and arithmetic coprocessors. IEEE 754-2008
covers both binary and decimal floating-point representations. In this chapter, we deal only
with binary representations.
• Arithmetic format: All the mandatory operations defined by the standard are
binary and two decimal, whose encodings are specified by the standard, and
which can be used for arithmetic. At least one of the basic formats is implemented in any
conforming implementation.
25
data interchange between different platforms and that can be used for storage.26
- Exponent: 8 bits
- Mantissa: 23 bits
- Exponent: 11 bits
- Mantissa: 52 bits
Example:.
Representing -6.75
*Convert to Binary:
- 0.75 × 2 = 1.5 → 1
- 0.5 × 2 = 1.0 → 1
1.1011times 2^2
26
*Determine Sign Bit:
- The exponent is 2.
- The mantissa is derived from the normalized form, excluding the leading 1:
Sign Bit: 1
Exponent: 10000001
Mantissa: 10110000000000000000000
Thus, the signed floating-point representation of -6.75 in IEEE 754 single precision is:
(-1)×(1+.10110000000000000000000)×(2^129-127)
References
27
3.computer organization and design the hardware and software
Fifth edition
5.
28