Sie sind auf Seite 1von 4

Notes: Ones and twos complement

Different ways of storing signed integers are presented. The number of bits used to
store an integer is a factor in integer storage in memory.
1. Sign bit integers
-3 ! 1011
+3 ! 0011
-5 ! 1101
+5 ! 0101
a. Disadvantages
Consider using a 4-bit architecture and perform the following: 4 + (-2)
Issues - how to dene addition?
2. Ones complement
Definition: The 1s complement of a binary value is obtained by changing the 1s to 0s and
the 0s to 1s.
Examples: a 1s complement system using 4-bit words.
+4 ! 0100 This value is nonnegative since the left-most bit is 0.
-4 ! 1011 Take the 1s complement of +4 to obtain the representation for 4.
0000 ! clearly this is 0.
1111 ! Its a negative, but which one? Its complement is 0000 or 0, hence this
is 0, which is still 0.
a. Rule for addition and a disadvantage of the 1s complement system.
Example of a 3-bit, 1s complement system

"#$% &'()*
+,, -
+,+ .
++, ,
+++ +
,,, +
,,+ /,
,+, /.
,++ /-

1
A microprocessor stores values in registers that are built into the microprocessor.
A general design for a microprocessor (CPU):
The ALU (arithmetic
and logic unit) is a
complex electrical
circuit that performs
arithmetic and logical
operations.
Todays processors
usually have 32 or 64-bit registers.
A typical register in the CPU (central processing unit) connects to other circuits via wires.
In this example, a
register is 16-bits. To
transfer the value to
another part of the
processor, each bit travels
on a wire. The 16 wires
are refered to as a bus.
ALU
The CPU
System bus
RAM
Registers
buses
bus
0 1 0 0 1 0 1 1
8-bit register storing a value
Register
etc
etc
bus
2
Dealing with the carry bit in a 1s complement system -
1 1 0
1 0 1
0 0 0
+
1
carry
1
1
1
1 0 0
+3
-2
+1
+
Examples: Performing addition. Are the sums correct?
a) 001 b) 110
101 110
110 1100 What do we do next in (b)?
b. Overow
What is overow and how do we know when it occurs?
Overow is when an arithmetic operation results in a value that doesnt t in the number
of bits supported by the system.
Try: 0 + (-3) Does overow occur assuming a 3-bit system?
Construct an example where overow occurs
3
3. Twos complement
Denition: The 2s complement of a binary value is obtained
by
(1) converting the value to its 1s complement, then
(2) adding 1 to that complement.
Study the values in the table. Do you see anything
unusual?
a. Why do we assign the value -4 to 100?
100 is clearly a negative. What happens if we complement it? It should be the positive
value. (Try it)
Since -1, -2, -3 are already used, it seems logical to assign -4 to it. But..
Try adding +1 to -4 (assuming it is 100), do we get the right answer? (Try it)
b. Rule for addition
Performing addition is similar to 1s complement, but with one
important difference.
Example: Using 4-bit words -
+6 = 0110. next take the 1s complement...
1001 finally, add 1 to this
0001
-6 = 1010
c. Overow
Discussion ...
4. Some examples... Using a 4-bit 1s and 2s complement system.
What are the largest positive and smallest negative integer values?
What happens if you add the two in each system?
How do you perform subtraction?

"#$% &'()*
+,, -
+,+ .
++, ,
+++ +
,,, /,
,,+ /.
,+, /-
,++ /0

1 1 0
1 0 1
0 0 0
+
1
carry
1
1
+3
-3
drop
the carry
4

Das könnte Ihnen auch gefallen