This presentation is about basic binary arithmetic and algebra.
Size: 198.5 KB
Language: en
Added: May 07, 2024
Slides: 13 pages
Slide Content
Binary Arithmetic
In today’s lesson we will look at:
•a reminder of how binary works
•adding binary numbers
•overflow
•complements
•negative numbers and subtraction
Denary
The number system most of us use is based on tens:
1234
101000 1100
x10x10 x10
As we move left, the
column headings
increase by a factor
of ten
In each column
we can have
tendifferent
digits (1 to 9
and 0)
This number is:
1 x 1000 + 2 x 100 + 3 x 10 + 4 x 1
That gives us one thousand
two hundred and thirty four
Binary
The binary system is based on the number two:
1011
28 14
x2x2 x2
As we move left, the
column headings
increase by a factor
of two
In each column
we can have
twodifferent
digits (0 or 1)
This number is:
8 + 2 + 1 = 11
It’s still eleven, it’s just written
down differently
Largest Numbers
0009
101000 1100
Binary behaves like
ordinary numbers in
lots of ways –think
of the largest
number we can write
with a given number
of digits...
0099
101000 1100
0111
28 14
Binary behaves in
the same way –e.g.
111 is seven.
Multiplying By 10
0025
101000 1100
In denary, if we
multiply by 10 then
the digits shift one
place to the left. 0250
0011
28 14
In binary, if we
multiply by 10 then
the digits shift one
place to the left0110
Adding Binary Numbers
•The same is true of adding numbers.
•Think about what happens when you’re
adding two normal numbers:
–we line the numbers up so that the units are
aligned
–we start on the right and add up each column
separately
–if the column total is 10 or more then we need
to carry
•Adding up in binary is exactly the same!
Example
0110
28 14
In this case, adding
is easy because
there’s nothing to
carry0001
0111
How can we check
the answer?
+
110 = six, and 1 = one –if we add six and one
together we should get seven = 111.
Example
0110
28 14
In this case, we have
two ones in the twos
column –what do we
do?0011
1
001
+
1
1 + 1 = 10, so we
need to carry one
1
Example
0110
28 14
Computers use a
fixed number of bits
to represent
numbers –usually 8,
16, 32, or 64 bits.
1011
001
+
What’s happened
here?01
There’s an extra digit –the answer is too big to fit!
This is called overflow.
Overflow
•Overflow is the name we give to the situation
where a number is too big to fit into the
allocated numbers of bits.
•This is an undesirable situation because we
don’t really know what the answer is.
•This can also happen when we’re sampling
data from the real world –e.g. if we try to
record a sound that’s too loud.
•Computers can get around this problem by
using multiple bytes to store numbers.
Subtraction
•You can subtract binary numbers in the same
way as we subtract ordinary numbers, e.g. by
borrowing if the bottom digit is smaller than
the top one.
•There is also another method that uses
complements.
•It uses the idea that subtracting a number is
the same as adding a negative number –e.g.
taking 2 away from 6 is the same as adding -2
to 6.
Complements
•Negative numbers in binary are often represented
using something called a twos-complement.
•A ones-complementtakes all of the digits and swaps
1s for 0s and vice versa –e.g. for the number 3:
00111100
•A twos-complementjust takes this number and adds
one to it:
1101
Thisis -3 in twos-
complementform
Example
0111
28 14
Imagine we want to subtract one from seven:
1111
110
+
01
There’s an overflowdigit –when we are subtracting
we just discard it. The answer is 0110 = six.
Here’s the seven:
One would be 0001;
the 1s-complement
would be 1110, and
the 2s-complement
would be 1111.