0% found this document useful (0 votes)
15 views

COA Assignment

COA

Uploaded by

abrahamasmamaw4
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

COA Assignment

COA

Uploaded by

abrahamasmamaw4
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 28

Bahir dar university

Bahir dar Institute of Technology


Department of cyber security computer
organization and architecture group
Assignment
Group member name member Id
1.Abraham Asmamaw.. ................1504838
2.Abel Asfaw..............….................….
3.Abel
4 .Abinet
5.Afomia.

Submitted to:-
ABRHAM.D(Assistant prof)

Table of contents .......... 1 Page

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

3.0 substraction of signed


and unsigned binary numbers................... 10
3 .1 substraction of signed binary .......................10
numbers
3.2 substraction of unsigned binary ............... 13
numbers
3.2.1 examples of unsigned binary numbers ........14

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 subtraction can be performed using borrowing, similar to decimal subtraction.

Binary multiplication mimics decimal multiplication through shifting and adding.

Binary division is akin to long division in decimal. For instance, dividing 1010 (10 in decimal)
by 10 (2 in decimal) results in:

1010 ÷ 10 = 101 (which is 5 in decimal)

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.

Floating-point representation is a method used in computing to represent real


numbers that can vary in magnitude. This representation allows for the encoding
of a wide range of values, including very small and very large numbers, which is
essential for scientific calculations, graphics, and engineering applications.

Signed and unsigned Addition of binary numbers

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

•Signed binary number addition is a method used to perform arithmetic


operations on binary numbers that can represent both positive and negative
values. This is essential in computer systems, where binary representation is the
foundation of data processing.

Signed-magnitude arithmetic is carried out using essentially the same methods


that humans use with pencil and paper, but it can get confusing very quickly. As
an example, consider the rules for addition:

(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:

- Positive numbers are represented as usual in binary.

- Negative numbers are represented by inverting the bits of the positive


number and adding one to the least significant bit (LSB).

Example

- To represent +5 in an 8-bit binary:

- Binary of 5: 00000101

- To represent -5:

- Invert the bits of +5: 11111010

- Add 1: 11111010 + 00000001 = 11111011

- So, -5 in two's complement is 11111011.

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.

3. Check for Overflow:

- 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

Case 1:one positive and one negative numbers

Let's add +5 and -3 using 8-bit two's complement representation.

1. Represent the Numbers:

- +5: 00000101

- -3:

- Binary of 3: 00000011

- Invert: 11111100

- Add 1: 11111100 + 00000001 = 11111101

2. Align and Add:

00000101 (+5)

+ 11111101 (-3)

______________

Perform the addition:

00000101

+ 11111101

______________

00000010 (Result)

The result 00000010 is 2 in decimal, which is correct since (5 + (-3) = 2).

7
• Case 2: Two Postive Numbers.

All steps the same for above

Let's take (+9 )whose binary is 0 1001 (augend)

and take (+4 ) whose binary is 0 0100 (addend)

Align and add:

0 1001(+9)

+ 00100(+4)

0 1101 (sum = +13)

Case 3: Positive Number and Larger Negative Number

Lets take (-9 ) whose binary is 10111

(+4 ) Whose binary is 00100

Align and add:

10111(-9)

+ 00100(+4)

11011 (sum = -5)

Case 4: two negative Numbers

Let's take (-9 ) whose binary is 10111

(-4 )Whose binary is 11100

Align and add:

10111(-9)

8
+11100(-4)

110011 (result)

The left first digit is ignored the result is:

10011 whose decimal is -13.

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.

Unsigned Addition of binary numbers


•Unsigned binary number addition is a method used to add binary numbers that
only represent non-negative values. Unlike signed binary numbers, which can
represent both positive and negative integers, unsigned binary numbers can
only represent zero and positive integers.

Representation of unsigned binary numbers


- Each bit represents a power of 2, starting from (2^0) for the least significant bit
(LSB).

- The leftmost bit (most significant bit, MSB) contributes the highest value.

For example, in an 8-bit unsigned binary number:

- 00000000 represents 0.

- 00000001 represents 1.

- 00000010 represents 2.

- 11111111 represents 255.

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.

3. Handle Overflow: If the result exceeds the maximum value representable


with the given number of bits, it wraps around (this is called overflow).

Example of Unsigned Binary Addition


Let's add two unsigned binary numbers: 1011 (which is 11 in decimal) and 0101
(which is 5 in decimal).

1. Align the Numbers:

1011 (11 in decimal)

+ 0101 (5 in decimal)

_________

2. Perform the Addition:

- Start from the rightmost bit:

- Bit 0:(1 + 1 = 10) → Write down 0 and carry over 1.

- Bit 1: (1 + 0 + 1 text{ (carry)} = 10) → Write down 0 and carry over 1.

- Bit 2: (0 + 1 + 1 text{ (carry)} = 10) → Write down 0 and carry over 1.

- Bit 3: (1 + 0 + 1 text{ (carry)} = 10) → Write down 0 and carry over 1.

- Since there are no more bits to add, write down the carry.

Putting it all together:

10
Carry: 1111

1011

+ 0101

_________

10000

• Result Interpretation:

The result is 10000, which is equal to (16) in decimal.

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.

Substraction of signed and unsigned binary numbers


Signed substraction of binary numbers
Signed binary number subtraction is a method used to subtract one binary
number from another, where the numbers can represent both positive and
negative values.

SUBTRACTION RULE: To subtract one number (subtrahend) from another

(minuend), take the twos complement (negation) of the subtrahend and add it
to the minuend.

Representation of Signed Binary Numbers


The most common methods for representing signed binary numbers are:

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.

2. Sign-Magnitude: In this representation, the leftmost bit indicates the sign (0


for positive, 1 for negative), while the remaining bits represent the magnitude.
However, this method is less commonly used due to complications in arithmetic
operations.

To subtract a signed binary number using two's complement, follow these steps:

1. Convert the Subtrahend to Two's Complement: This transforms the


subtraction into addition.

2. Add the Minuend and the Two's Complement of the Subtrahend: Perform
binary addition.

3. Handle Overflow: If there is an overflow (i.e., a carry out of the most


significant bit), it can generally be ignored in two's complement arithmetic.

Example of Signed Binary Number Subtraction


Case 1: substract positive and negative numbers

subtract (5) from (-3) using 4-bit signed binary representation.

1.Represent the Numbers

- 3 in two's complement:

- First, represent (3) in binary: 0011.

- Invert the bits: 1100.

12
- Add (1): 1100 + 0001 = 1101. So, (-3) is 1101.

- 5 in binary:

- (5) in binary is 0101.

2. Convert the Subtrahend to Two's Complement

Since we want to subtract (5),we need to find its two's complement:

- Represent (5): 0101.

- Invert the bits: 1010.

- Add (1): 1010 + 0001 = 1011. So, (5) in two's complement is 1011.

3.Add the Minuend and the Two's Complement of the Subtrahend

Now we add (-3) (1101) and (-5) (1011):

Carry: 111

1101 (-3)

+ 1011 (-5)

_________

11000

4.Interpret the Result

The result is 11000. Since we are using 4 bits, we only keep the last four bits,
which gives us 1000.

- Now, interpret 1000:

- The leftmost bit is 1, indicating it is negative.

-To find its value, we convert it back to decimal:

- Invert the bits: 0111.

13
- Add (1): 0111 + 0001 = 1000. So, 1000 represents (-8).

Thus, (-3 - 5 = -8), which is consistent with our expectations.

Case 2: substraction of two negative numbers

e.g 1010 represent (-6)

1100 represents (-4)

then substract from the minued.first find the twos complemt of -4 then add.the
twos complemt of -4 is 0100.

1010

+ 0100

1110

the result represents -2 decimal number

Check: it start by 1 then the number is negative.add the left three one bit.

-8+4+2=-2.

Unsigned substraction of binary numbers


Unsigned binary number subtraction the process of subtract one binary number
from another when both numbers are non-negative. Unlike signed binary
numbers, unsigned numbers do not have a sign bit, allowing for a larger range of
positive values.

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).

Therefore, we need to look at some examples involving both positive and


negative numbers. Recall the rules for addition:

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.

When substracting two unsigned binary numbers the things to consider is

.Borrowing Method: Similar to decimal subtraction, where you borrow from


higher bits if the current bit in the minuend is smaller than the corresponding bit
in the subtrahend.

. Two's Complement Method: Convert the subtrahend to its two's complement


and add it to the minuend.

Examples of unsigned binary number substraction


for example1 substracting (5) from (12) using 4-bit unsigned binary
representation.

- represent 12 in binary:

- (12) in binary is 1100.

- 5 in binary:

- (5) in binary is 0101.

Align the Numbers for Subtraction

-1100 (12)

- 0101 (5)

Perform the Subtraction

Start from the rightmost bit:

15
- Bit 0: (0 - 1) → Borrow from next column. Current column becomes (10 - 1 = 1).

- Bit 1: (0 - 0) → Result is (0).

- Bit 2: After borrowing, we have (0 - 1) → Borrow from next column again. This
column becomes (10 - 1 = 1).

- Bit 3: Now we have (1 - 0) → Result is (1).

The result of the subtraction is:

1100

- 0101

--------

0111

The result 0111 in binary represents (7) in decimal.

Example 2

Subtract 1100011(99) from 1001111 (79)

1001111(79)

- 1100011(99)

1101100 which is -20 decimal number.

- Applications: Unsigned binary subtraction is commonly used in digital circuits,


computer systems, and programming where only non-negative values are
involved.

Multiplication of signed and unsigned binary numbers


Multiplication of unsigned binary numbers
Unsigned binary number multiplication is the process of multiplying two non

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.

To illustrate simple computer multiplication, we begin by writing the multiplicand


and the multiplier to two separate storage areas. We also need a third storage
area for the product. Starting with the low-order bit pointer is set to each digit of
the multiplier. For each digit in the multiplier, the multiplicand is “shifted” one bit
to the left. When the multiplier is 1, the “shifted” multiplicand is added to a
running sum of partial products. Because we shift the multiplicand by one bit for
each bit in the multiplier, a product requires double the working space of either
the multiplicand or the multiplier.

Compared with addition and subtraction, multiplication is a complex operation,


whether performed in hardware or software. A wide variety of algorithms have
been used in various computers. The purpose of this subsection is to give the
reader some feel for the type of approach typically taken. We begin with the
simpler problem of multiplying two unsigned (nonnegative) integers, and then we
look at one of the most common techniques for multiplication of numbers in twos
complement representation

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).

for example multiply 1011(11) with 1101(13)

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.

Multiplication of signed binary numbers

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

Example illustrates the use of Booth’s algorithm to

multiply −3 × 5 using signed 4-bit two’s complement

numbers.

Negative 3 in 4-bit two’s complement is 1101. Extended

to 8 bits, it is 11111101. Its complement is 00000011.

When we see the rightmost 1 in the multiplier, it is the19 beginning of a string of


1s,so we treat it as if we're string 10.

1101

❌ 0101

00000011

11111101

00000011

19
11111101

100111110001 using 8 right most bits we ha ve -3*5=-15.

Division of signed and unsigned binary numbers


•Th e reciprocal operation of multiply is divide, an operation that is even less frequent and even
more quirky. It even off ers the opportunity to perform a mathematically invalid operation:
dividing by 0.

•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:

•Dividend =Quotient ×Divisor + Remainder

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

these two choices, thereby simplifying binary division.

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.

Division of signed binary numbers

20
Examples of signed binary number division

Divide the value –14 (expressed using 8-bit signed two’s complement

representation) by 2.

We start with the two’s complement representation for –14:

11110010

and we shift right one place (carrying across the sign bit), resulting in:

11111001

which is decimal –7 = –14 ÷ 2.

Division of unsigned binary numbers

21

21
Examples of unsigned binary number division
Example Consider the division of a dividend X = 32 = (0100000)
and a divisor D=6=(0110).

r0 = X 010000 0 Initial values set q1=1.

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

2r2 0 1 0 0 0. Set q3=1

-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

Divide the value 12 (expressed using 8-bit signed two’s complement


representation) by 2.

We start with the binary value for 12:

00001100

and we shift right one place, copying the sign bit of 0, resulting in:

00000110

which is decimal 6 = 12 ÷ 2.23

Floating point representation of signed and unsigned binary


numbers
•In scientific notation, numbers are expressed in two parts: a fractional part and an exponential
part that indicates the power of ten to which the fractional part should be raised to obtain the
value we need. So to express 32,767 in scientific notation, we could write 3.2767 × 10^4.

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

•A designer of a fl oating-point representation must fi nd a compromise between the

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.

.•Floating-point numbers are usually a multiple of the size of a word.

Floating point representation of signed binary numbers


•Signed floating-point representation is a mechanism that is used to represent real numbers,
including both positive and negative values, in a binary format.

•This representation is essential in computing for handling a wide range of values, including
very small and very large numbers.

Components of Floating Point Representation

The floating-point format typically consists of three main components:

*Sign Bit (S): Indicates the sign of the number.

- 0 for positive numbers.

- 1 for negative 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.

The general formula for representing a floating-point number is:

+S ×B^ +E

This number can be stored in a binary word with three fields:

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.

•IEEE Standard for Binary Floating-Point Representation

The most important floating-point representation is defined in IEEE Standard 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.

IEEE 754-2008 defines the following different types of floating-point formats:

• Arithmetic format: All the mandatory operations defined by the standard are

supported by the format. The format may be used to represent floating-point

operands or results for the operations described in the standard.

• Basic format: This format covers five floating-point representations, three

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.

• Interchange format: A fully specified, fixed-length binary encoding that allows

25
data interchange between different platforms and that can be used for storage.26

•Single Precision (32 bits)

-Sign Bit: 1 bit

- Exponent: 8 bits

- Mantissa: 23 bits

Double Precision (64 bits)

- Sign Bit: 1 bit

- Exponent: 11 bits

- Mantissa: 52 bits

#Example of Signed Floating Point Representation

Example:.
Representing -6.75

*Convert to Binary:

- The integer part 6 in binary is 110.

- The fractional part .75 in binary:

- 0.75 × 2 = 1.5 → 1

- 0.5 × 2 = 1.0 → 1

- So, .75 in binary is .11.

- Therefore, 6.75 in binary is 110.11.

*Normalize the Number:

- Normalize 110.11 to scientific notation:

1.1011times 2^2

26
*Determine Sign Bit:

- Since the number is negative, the sign bit S = 1.

*Calculate the Exponent:

- The exponent is 2.

*Calculate the Mantissa:

- The mantissa is derived from the normalized form, excluding the leading 1:

- 10110000000000000000000 (23 bits).

* Combine All Parts:

- Putting it all together:

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)

Floating point representation of unsigned binary numbers

References

1.computer organization and architecture

Design for performance William stallings

2.The essential of computer organization and architecture fourth


edition

27
3.computer organization and design the hardware and software

Interface David A Patterson and John L Hennessy

4.The essential of computer organization and architecture

Fifth edition

5.

28

You might also like