Presentation is loading. Please wait.

Presentation is loading. Please wait.

Integers’ Representation. Binary Addition. Two's Complement.

Similar presentations


Presentation on theme: "Integers’ Representation. Binary Addition. Two's Complement."— Presentation transcript:

1 Integers’ Representation. Binary Addition. Two's Complement.
Unsigned number representation Binary Addition, Subtraction. Overflow of unsigned numbers. Negative integers’ representation. Sign Magnitude. Complement number systems One’s complement Two’s complement. Addition. Subtraction. Overflow. Textbook: P&H Ch3, Central Connecticut State University, MIPS Tutorial. Chapter 8. Wakerly: Chapter 2. NUMBER SYSTEMS AND CODES

2 Number representation requirements
The representation of the numbers in the computers should satisfy the following requirements: Be comfortable for keeping them in the memory (take less hardware for storing). Be comfortable for calculations (need less hardware and act faster). The operations we do with the numbers in the computers are: Addition Subtraction Multiplication Division Comparison

3 Number representation examples
We can represent at most 4 unsigned numbers with these 4 patterns. This way: Or this way: For transmission through the noisy channels we use some redundancy to be able to recover the information after transmitting.   We use only 2 patterns from 8 for representing 2 numbers. Then if at the receiver side we got “110” then we can assume that it was “1” when it was sent. Number of possible patterns of N bits  =  2N How to assign these patters to the numbers we want to represent ? It depends on our choice based on requirements of the task we want to implement.

4 Unsigned number representation
The representation of the decimal positive numbers in natural binary positional form in the computers is called “Unsigned” representation. This is the unsigned representation of positive numbers 0-7 on 3 bits.

5 Binary Addition Algorithm
Definition: Two bit patterns representing two integers are manipulated to create a third pattern which represents the sum of the integers. To add two bits: Count the number of ones in a column and write the result in binary. The right bit of the result is placed under the column of bits. The left bit is called the "carry out of the column". Binary Addition Table the carry into the column | <--- oprnd1 oprnd2 ^ the carry out of the column

6 Binary addition of N bits
As the decimal results are correct then the binary arithmetic works correctly. To add two N-bit (representations of) integers: Proceed from right-to-left, column-by-column, until you reach the leftmost column. For each column, perform 1-bit addition. Write the carry-out of each column above the column to its left. The bit is the left column's carry-in. = = = An addition example with 4 bits 0111 ==> ==> ==> ==>

7 Binary addition details
Are the results correct for all 3 cases? Usually the operands and the result have a fixed number of bits (usually 8, 16, 32, or 64). These are the sizes that processors use to represent integers. If the bits in the leftmost columns of the sum are zero, include them in the answer to keep the result the same bit-length as the operands. Compute the carry-out of the leftmost column, but don't write it as part of the answer (because there is no room.) The second case is not correct because 7+9 != 0 0011 0001 ---- 0100 1111 0111 1001 ---- 0000 0111 0001 ---- 1000

8 Correct Unsigned Binary Addition
Unsigned overflow When the bit patterns are regarded as representing positive integers (unsigned binary representation), a carry-out of  1  from the leftmost column means the sum does not fit into the fixed number of bits. This is called Overflow. When the bit patterns are regarded as representing positive and negative integers (as described in the last pages of this chapter), then a carry-out of 1 from the leftmost column is not necessarily overflow. 1111 0111 1001 ---- 0000 0111 0001 ---- 1000 Correct Unsigned Binary Addition The result is CORRECT only if the CARRY OUT of the high order column is ZERO.

9 Unsigned number representation Pros and Cons
Unsigned subtraction An Example with 4 bits minuend subtrahend difference The borrowing of the values is done from the previous columns similar to 10 based arithmetic. Just instead of 10 the 2 is borrowed (10 binary). Unsigned number representation Pros and Cons Unsigned numbers represent only positive integers Addition is simple. Subtraction is complex.


Download ppt "Integers’ Representation. Binary Addition. Two's Complement."

Similar presentations


Ads by Google