Download Understanding Integer Representations in Computer Arithmetic: ALU, Unsigned, Sign and more Lecture notes Logic in PDF only on Docsity!
Computer
Arithmetic:
Arithmetic and
Logic Unit (ALU)
Arithmetic & Logic Unit (ALU)
- Part of the computer that actually performs arithmetic and logical operations on data
- All of the other elements of the computer system are there mainly to bring data into the ALU for it to process and then to take the results back out
- Based on the use of simple digital logic devices that can store binary digits and perform simple Boolean logic operations
Integer Representations
- In the binary number system arbitrary numbers can be represented with: - The digits zero and one - The minus sign (for negative numbers) - The period, or radix point (for numbers with a fractional component)
- For purposes of computer storage and processing we do not have the benefit of special symbols for the minus sign and radix point
- Only binary digits (0,1) may be used to represent numbers
Integer Representations
- There are 4 commonly known (1 not common) integer representations.
- All have been used at various times for various reasons. 1. Unsigned 2. Sign Magnitude 3. One’s Complement 4. Two’s Complement 5. Biased (not commonly known)
1. Unsigned (Cont’d.)
Semester II 2014/2015 9
2. Sign-Magnitude
conventions used to represent^ There are several alternative negative as well as positive integers Sign-magnitude representation is the simplest form that employs a sign bit
Drawbacks:
Because of these drawbacks, sign-magnitude representation is rarely used in implementing the integer portion of the ALU
- All of these alternatives involve treating themost significant (leftmost) bit in the word as
- a sign bitIf the sign bit is 0 the number is positive
- If the sign bit is 1 the number is negative
- Addition and subtraction require aconsideration of both the signs of the numbers and their relative magnitudes tocarry out the required operation
- There are two representations of 0
2. Sign-Magnitude (Cont’d.)
- Left most bit is sign bit
- 0 means positive
- 1 means negative
- +18 = 00010010
- -18 = 10010010
2-
3. One’s Complement
- Used to get two’s complement integers.
- Nowadays, it is not being applied to any of the
machines.
- Stated in this slide for historical purpose.
Semester II 2014/2015 13
5. Biased
- an integer representation that skews the bit
patterns so as to look just like unsigned but actually represent negative numbers.
Semester II 2014/2015 15
Table 10. Alternative Representations for 4-Bit Integers
Range of Numbers
- 8 bit 2s complement
- +127 = 01111111 = 2^7 -
- -128 = 10000000 = -2^7
- 16 bit 2s complement
- +32767 = 011111111 11111111 = 2^15 - 1
- -32768 = 100000000 00000000 = -2^15
2-
Negation
- Twos complement operation
- Take the Boolean complement of each bit of the integer (including the sign bit)
- Treating the result as an unsigned binary integer, add 1
- The negative of the negative of that number is itself:
+18 = 00010010 (twos complement) bitwise complement = 11101101
-18 = 11101110 (twos complement) bitwise complement = 00010001
Negation Special Case 2
-128 = 10000000 (twos complement) Bitwise complement = 01111111 Add 1 to LSB + 1 Result 10000000 So: -(-128) = -128 X Monitor MSB (sign bit) It should change during negation
OVERFLOW RULE:
If two numbers are added,
and they are both positive or
both negative, then overflow
occurs if and only if the
result has the opposite sign.