Transcript Document

IT Systems
Number Operations
EN230-1
Justin Champion
C208 – 3273
www.staffs.ac.uk/personel/engineering_and_technology/jjc1
IT Systems

Contents

Maths
•
•
•
•


Addition
Subtraction
Multiply
Division
Negative numbers
How it actually works
• Half adder
• Full Adder
IT Systems

Different numbers systems

Last week we looked at different common number systems
• Hexadecimal
• Binary
• Decimal



These number systems unless we could do something with
them
Computers are good calculations we will look methods of
doing the maths
First job is to convert the numbers into a common format
• Methods of this were discussed last week in lecture 4
IT Systems

Binary Addition

This works in the same way as the decimal
system
• Add
1
+0
1
• The issue becomes when we have
1
+1
??
• This sum is done in the same way decimal, the
value is written in the column and a carry bit is
then added to the next column
1
+1
10 = Decimal 2
IT Systems

Binary Addition (continued)

More examples
• As discussed last week ensure that both lines
have the same number of values so
• Becomes
010
+0111011
0000010
+0111011
• Workings
Carries
1
0000010
+0111011
0111101
IT Systems

Computer Architecture

6811
• Has a special register which stores the carry bit if
the number is bigger than the register you are
working upon
• Register A, B are both 8 Bits

All processors have this register
IT Systems

Binary Subtraction


The same technique is used as decimal
Try
1
-0
1
111
- 100
011
11000
- 10111
00001

If you are having problems with this concept there is
nothing wrong with converting to decimal carrying
out the maths then converting back to binary
IT Systems

Binary Multiplication & Division

Special case where multiplication or division are by
a divisor of 2
111
* 10
1110

Dec 7
Dec 2
This could be done by the same method as used for
decimal
• Faster method is to use Binary Bit Shifting
IT Systems

Binary Bit Shifting

This is moving all of the bits
• Move them towards the big endian for multiplication
• Move them towards the little endian for division

One movement would equal a change by 2
• If you were multiplying by 8
• You would move towards the big endian 4 times
IT Systems

Multiplication

Try this

If the numbers are NOT multiples of 2
101
* 100
or
1000
/ 100
• You have to do the work the same as the decimal
method

For the remainders we will ignore as this will
end up complicated
IT Systems

Negative numbers
Obviously it is possible to end up with negative
numbers
 These number are represented by different
methods

•
•
•
•
Signed Magnitude
One’s Complement
Two’s Complement
Excess
IT Systems

Signed Magnitude
 The big endian is used to indicate if the value is positive or
negative
• 00001100 == +12
• 10001100==-12


One’s Complement
 Positive numbers do not change
 Negative numbers flip the bits
 The big endian as with signed magnitude indicates a positive or
negative value
Flipping the bits
 All 1’s become 0 and all 0’s become 1’s
So 0001001 becomes 1110110
IT Systems

Two’s Complement
First of all this is the same as 1’s complement
 The value of 1 is added to the result


Excess 2(m-1) = 8 bits = 27
The maximum value is added to the binary
number
 +7 = 10000111
 -7 = 01111001

IT Systems

Whichever system is used it must be check on
the architecture.
If your maths are based upon 2’s complement
and you use 1’s the answers will be very
different
 2’s complement is the common used method

• The ease of maths is the reason for this
IT Systems

Maths with the 2’s complement



12 + -7
12 = 1100
-7 = 1001
1100 Dec 12
+1001 Dec -7
0101 Dec 5

The fifth bit is thrown away and will be stored by the
overflow bit
IT Systems

Maths on Hexadecimal numbers

As with Binary the same method as decimal is used
7
Dec 7
9
Dec 9
+2
Dec 2
+2
Dec 2
9
Dec 9
B
Dec 11
IT Systems

How it works ?


So after all of this how does the computer actually add
the numbers
A series of logic gates
•
•

Sum = A . B
Carry = A + B exclusive OR
This will add 2 binary numbers together
•
And is commonly referred to as a half adder
IT Systems

How it works ?


Half adder adds 2 binary values together and stores one
bit in the carry bit
A full adder accepts the carry bit as a input and also has
a carry bit as a output.
•
•
These full adders are then put into sequence connecting to each
other
So for a 8 bit adder we would have 8 of them in a row
IT Systems

Summary of what we have discussed

Maths
•
•
•
•


Addition
Subtraction
Multiply
Division
Negative numbers
How it actually works
•
•
Half adder
Full Adder