Team Geek present 'All thing's Binary' - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Team Geek present 'All thing's Binary'

Description:

Underflow ... Therefore the number is effectively forgotten about, this is called underflow. Example ... simple example of underflow. Much simpler than overflow ... – PowerPoint PPT presentation

Number of Views:159
Avg rating:3.0/5.0
Slides: 23
Provided by: mjew4
Category:

less

Transcript and Presenter's Notes

Title: Team Geek present 'All thing's Binary'


1
All Things Binary!
A short presentation designed to give you a crash
course in binary including....
Binary arithmetic Conversions using
binary Floating/fixed point representation Normali
sation
If you have any questions/queries or you spot any
mistakes, that includes spelling errors or simply
if you want to know more about Team Geek, contact
one of us using the following email address
  • info_at_teamgeek.co.uk

Disclaimer This is not all the information you
could ever need about binary, it is just a
resource which should compliment your notes and
help you to understand the various elements of
binary.
2
Comparing binary to denary
First of all lets look at some of the
differences between binary, and denary (our
normal number system)
3
Understanding denary
Lets look at our numeric system first
(Denary) Denary uses a column system Example
193 -
Here we have 3 in the ones column, 9 in the
tens column, and 1 in the hundreds column This
literally means (3 x 1) (9 x 10) (1 x 100)
193 We refer to denary as base 10. This
means that all the columns in this numeric system
are powers of ten. The column headings could be
written like this
4
Now to understand binary
Lets now look at Binary
Binary also uses a column system
We refer to Binary as base 2. This means that all
the columns in this numeric system are powers of
two. it also means that we can only use the first
2 digits (0 1). The column headings could be
written like this
The column headings could also be written like
this
We would write the previous example 193 like this
Here we have 1 in the 128s column, 1 in the 64s
column, and 1 in the 1s column This literally
means (128 x 1) (64 x 1) (1 x 1)
193 Each of the 1s and 0s in a binary number is
called a bit, normally 8 bits make a byte.
5
On to octal...
Lets now look at Octal
Octal also uses a column system
We refer to Octal as base 8. This means that all
the columns in this numeric system are powers of
8, it also means that we can only use the first 8
digits (0 7). The column headings could be
written like this
The column headings could also be written like
this
We would write the previous example 193 like this
Here we have 3 in the 64s column and 1 in the 1s
column This means (64 x 3) (1 x 1)
193
6
Saving the best till last, Hexadecimal
Lets now look at Hexadecimal (Hex for short)
Hex also uses a column system
We refer to Hex as base 16. This means that all
the columns in this numeric system are powers of
16, it also means that we can only use the first
16 digits, here we have a problem, as there are
only 10 numeric digits(0-9) so we use letters as
the next 6 digits (0 1 2 3 4 5 6 7 8 9 A B C D E
F) The column headings could be written like
this
The column headings could also be written like
this
We would write the previous example 193 like this
Here we have a C in the 16s column and 1 in the
1s column (C 12) This literally means (16 x
12) (1 x 1) 193
7
Some more examples
There are blank spaces, see if you can fill them
in (you should be able to do so by now!) Note
binary numbers are grouped in half bytes (known
as nibbles) for easier reading.
Denary Binary 32 0010 0000 110 0110
1110 123 0111 1011 36 0010 0100 26 0111
1110 83 ____ ____ 106 ____ ____ 5 ____
____ ____ 0010 0101 ____ 0101
1001 ____ 1101 0110 If you want to check
your answers, check with your mates, check with
your teacher or email us (addresses available on
the first slide).
8
Simple binary arithmetic - addition
To add binary we use the same principal as denary
addition
Lets add 56 to 56
Denary
2 2 4 4 4 8 6 6 12 2 ? we cannot
have 12s in denary column, so we carry a 1 to
the next column
56 56 12_ 56 56 112_
Binary
0011 1000 0011 1000 1 0000 0011
1000 0011 1000 0111 0000 01110000 which
equals 112
0 0 0 0 1 1 1 1 2 ? we cannot have
2s in a binary column, so we carry a 1 to the
next column 1 1 1 3 ? we cannot have 3s
in binary, so we carry a 1 to the next column
and put a 1 in that current column
9
Simple binary arithmetic - subtraction
To subtract binary we use the same principal as
denary subtraction
Lets subtract 32 from 51
Denary
3 - 2 1 2 - 2 0 1 - 6 -1? we cannot have
negative numbers in the middle of a number
column, so we borrow a 10(or 100 etc) from the
next column, and now do 11 2 which equals 9
54 11 3 2 - 1 9 _ 19 51 40 -
11 _
1) 2) 1) 2)
Binary
0011 0011 0010 0000 - 0001 0011 00010011
which equals 19 00110 20011 0010 1000 - 0000
1011 00001011 which equals 11
1 - 0 1 1 - 1 0 0 - 1 -1 ? we
cannot have a negative bits in a binary
column, so we borrow a bit from the next
column
10
Negative binary sign and magnitude
There are two main ways of representing negative
numbers in binary. The first of which is sign and
magnitude In sign and magnitude we use one bit
to represent the sign of the number and the rest
of the bits to represent the magnitude of the
number. The bit used to represent the sign is
always the leftmost bit (this is also known as
the most significant bit or MSB) an MSB of 0
denotes a positive number and 1 denotes a
negative number (in the following examples we are
using 9 bit bytes) Example 1 56 Example 2 -
56 M M S S B B \/ \/ 0 00111000 1
00111000
  • Have a go at these conversions...
  • Denary Binary
  • 12 0 0000 1100
  • 115 0 0111 0011
  • 36 1 0010 0100
  • 126 1 0111 1110
  • 73 _ ____ ____
  • -106 _ ____ ____
  • ____ 0 0010 0011
  • ____ 1 0101 1010

11
Negative binary Twos Complement
The second way of representing negative numbers
is Twos Complement In Twos Complement the
whole byte is used to represent a negative
number. To make a negative number, we write out
the positive binary number, and then go along,
the byte from right to left until we reach the
first 1 in the byte, we then flip all of the
bits to the right of this first 1. this means all
of the 1s become 0s and all of the 0s become
1s. Example 1 56 Example 2 -
56 00111000 00111000 Positive
56 00111000 First 1 11001000
Flipped bits First 1 Unchanged Bits
  • Time for you to have a go again...
  • Denary Binary
  • 13 0000 1101
  • 83 0101 0011
  • 36 1101 1100
  • 126 1000 0010
  • 63 ____ ____
  • -116 ____ ____
  • ____ 0010 0011
  • ____ 1101 1010

12
Fixed point representation
A fixed-point number is the one easiest to
understand. This is just a number with a fixed
number of digits after the decimal point. For
example the number 8.25 or 12.75. These numbers
can also be represented in binary. Denary to
binary   Consider the number 12.75   We go from
left to right and add a 1 every number, which
will not make the overall number more than
12.75   After 1 we, start going down in negative
powers of 2. i.e. 2-1, then 2-2 ..etc This
gives us the fractional numbers for the
headings.   Note - the limitation of this is that
if we have a number such as 3.77 we need to round
it, to the nearest available binary number 3.75.
Now its time for an example.. Continued on
the next page...
13
Fixed point representation continued
First, you should be able to find that 12 is 1100
in binary. Then we can add ½ because it will
give 12.5 which is less than 12.75 Next we can
add ¼ because 12.75 is equal to our
goal. Finally the rest can be zerod because
we have reached our goal. And its really as
simple as that! Now lets look at the opposite
conversion
14
Fixed point representation continued
Binary to Denary   10011100 in fixed point
binary. For the purposes of this example we can
assume, that the decimal point occurs after the
4th bit. This usually depends on how many bytes
the number is using. Then we read off the
denary numbers which have a 1 next to them 8
1 ½ ¼ 9.75 Its even easier than
converting to binary from denary, its just
common sense really! Are you ready for some
harder stuff now? Lets continue....
15
Floating point representation
Denary to Binary   Floating point binary works
like standard form in denary. There is a
mantissa, which is the main part of the number.
Then there is the exponent, which holds the
number of places to move the point.   Consider
the number 18.625   First of all convert this
number into binary fixed point as
before. This gives 10010.1010 (in
binary)   In floating point the decimal point
should be before the first 1 which is 5 places to
the left.   Mantissa 0 100101010 Exponent 5
000101 Therefore this is 0.100101010
(mantissa) x 25 (exponent)   Using a 10 bit
mantissa and a 6 bit exponent is a common way of
showing floating point numbers.
The fun continues....
16
Floating point representation continued
Binary to Denary   Consider the following 10 bit
mantissa and 6 bit exponent number   Mantissa
Exponent   0 110011010 000100   The
exponent shows that the decimal place must be
moved 4 places to the right. So it becomes,
1100.1101   Which converted into decimal
is 8 4 ½ ¼ 1/16   12.8125
Got that? Now the boring stuff....
17
Normalisation of binary numbers

We use normalisation in every day life, and is
commonly known as standard form. For example
should we want to represent 10,000 in standard
form we would say it was 1x104 although one could
argue that this can also be written as 10x103
which technically makes no difference as both
forms lead to the number 10,000. However the
mathematicians among you would argue that 1x104
is the correct standard form and you would be
correct. It is defined that a number is only in
standard form when the mantissa (the number
before the multiplier, whether the multiplier is
102 or 210) is higher than 1 and lower than 10.
Then the number is considered to be in standard
form, or in a normalised form.   The same is true
of the binary number system, although there are
certain differences. The number before the
multiplier (exponent) can be referred to as the
mantissa or the significand, but for the purposes
of this page I will be referring to this as the
mantissa. In the binary number system the
significand must be greater than, or equal to .1
and is always lower than 1. For example, consider
2 bytes, the first 10 bits represent the sign and
mantissa and the final 6 represent the
exponent   0101010000000010 splits up
to   Sign Mantissa Exponent 0 101010000 00001
0  
If youve got your head around that part,
continue to complete the example
18
Normalisation of binary numbers continued

Combining the sign, mantissa and exponent gives
us 0.101010000 x 22 (This example is already
normalised) what this means is that the decimal
point shifts two places to the right so it
becomes   010.1010000 which is the same as 2.625
in the denary system   How precise the floating
point number is depends entirely upon how
accurate the mantissa is, for example the
mantissa in the above example uses 9 bits whereas
it could be limited to less. Therefore if the
number was 0.10101010 it would be stored as
0.10101 if the mantissa was only 5 bit, therefore
you have lost the accuracy in the
number. Summary DenaryA number is only
normalised when the mantissa is higher than 1,
and lower than 10 BinaryA number is only
normalised when the mantissa is higher than .1,
and lower than 1. So effectively all binary
numbers should start 01, otherwise they arenot
normalised binary numbers  
Lasted this long? Well done, were nearly done!
19
Issues with binary
Floating and fixed point numbers will be accurate
to the smallest number they can represent.
Therefore sometimes when using binary we can come
across certain errors. Round-Off Errors Often
we cannot represent a denary fraction exactly
even if we allow many bits in memory. Therefore
the number stored is "rounded off" to the closest
possible binary equivalent. ExampleConsider the
denary number 5.5627, convert this to an 8 bit
binary number which has 4 bits after the
point. This might seem easy at first but look at
the problem we face when trying to convert it to
binary if we try and make the closest number
to 5.5627 we can only make the number 5.5625, the
extra 0.0002 needed to make 5.5627 cannot be
represented using an 8 bit byte which has 4 bits
after the point. This is called a rounding error.
Time for you to do some work!Using an
unlimited number of bits, try to express the
above denary number, 5.5627 using binary.If you
solve this one let us know, were dying to know.
Honest.

Theres more to come yet
20
Issues with binary continued
Truncation ErrorsOften, in either floating or
fixed point systems, results are calculated with
too many places of accuracy to be represented. We
get this type of error when trailing bits are
truncated to fit the result in the memory
location available. ExampleConsider the denary
number 17.5625, express this using binary. You
are to use a 8 bit byte, which has 3 bits after
the point. We can try to make this number
using binary, and in fact if you had the column
heading 1/16 available you could easily make
the number, it would be 10001.1001. But using the
bits available the closest number we can make is
1.5. The last bit is chopped off because you only
have 3 point available after the point. The
result has been truncated. Note its not just
when converting numbers to binary that these
types of error can occur, it can happen quite
easily when adding two binary numbers or
subtracting two binary numbers.Can you think of
another example? Try it out, these examples are
hard to think of, half the time they dont work
when you try to make them!

And more
21
Issues with binary continued
Overflow When a calculation gives us a result
that is too large to be represented, it is said
that overflow has occurred. ExampleIn denary 17
18 35, lets try and do the same calculation
using binary using a 6 bit number with the first
bit representing the sign (remember 1 is
negative, 0 is positive).1710 0100012 1810
0100102 010001 010010-----------
100011 1000112 -310 Do you see the problem
here? The answer in denary should have been 35,
but using binary addition weve got the answer
to be -3. This is because the number is too big
to be represented, this is an example of
overflow. This is quite a hard concept to grasp,
but something which you must understand about
binary, can you imagine if nobody realised this
problem? All the maths we know to be true would
have been proven wrong!If your struggling, see
your teacher, ask us or ask your neighbour.

A nice one to finish with
22
Issues with binary continued
Underflow A result is produced that is smaller
in magnitude than the smallest number that can be
represented. Therefore the number is effectively
forgotten about, this is called
underflow. ExampleUsing a nibble (4 bits) in
binary, represent the denary number 4.5. If you
have 1 bit after the point, its certainly
possible. Now try to represent 4.5 using
normal column headings (without a bit after the
point) for a nibble.. The closest you can get
is 4, or 5 if you use 0101. The result/number you
want to represent is smaller than the smallest
number which you can represent (in this case 1)
therefore the number is forgotten about. This is
a simple example of underflow. Much simpler than
overflow dont you agree?
Write a Comment
User Comments (0)
About PowerShow.com