binary hex conversion ppt

Download Report

Transcript binary hex conversion ppt

Computer science
ADDING BINARY NUMBERS
CONVERT DECIMAL TO BINARY
CONVERTING HEX TO BINARY
CONVERTING BINARY TO HEX
REMEMBER TO PLAY THE CHANGING HEXADECIMAL TO DECIMAL VIDEO
objectives
MUST:
be able to add two 4 bit binary numbers together
Understand that binary numbers are held in 8 bit fixed strings on computers
Be able to explain how to convert binary to decimal in plenary
SHOULD:
be able to add tow 8 bit binary numbers together
Be able to add and convert binary numbers into 8 bit fixed strings
Be able to explain how to add two binary numbers together
COULD:
Be able to recognise and explain binary overflow when adding tow 8 bit binary
numbers
Starter task refresh binary numbers
CONVERT DECIMAL TO BINARY
In your exercise book write down the following
decimal numbers
Convert them to binary
You have 5 minutes
Nb show your workings
DECIMAL TO BINARY
10
100
1000
10000
11232
34
7001
CONVERT DECIMAL TO BINARY
In your exercise book write down the following
BINARY numbers
You have 5 minutes
Nb show your workings
REFRESH TWO
CONVERT BINARY TO DECIMAL
1001
11010111
00000001
30000300
00100100
00000001
ADDING BINARY NUMBERS
Adding binary numbers is very similar to the way
we add base 10 numbers
For example lets add 367 to 284
3
6
7
2
8
4
6
5
1
To explain the above:
7+4 =11,so we write down 1 and carry the 1
6+8+1=15,so we write down 5 and carry the 1
3+2+1=6
These are then carried over values from the previous column
Adding binary continued
when adding binary numbers we follow the
same process ,but 1+1 =2 which is written as 10
in Binary:
The first few numbers in Binary are
Base 10
binary
1
1
2
10
3
11
4
100
5
101
6
110
Binary addition
Lets look at binary addition 1011+1101
1
0
1
1
1
1
0
1
1
1
0
0
0
1
1
1
1
1+1 =10(in binary)
So we write down 0 and carry the 1
1+0+1=10(in binary)
So we write down 0 and carry the 1
0+1+1=10(in Binary)
So we write down 0 and carry the 1
1+1+1=11(in binary)
So we write down 1 and carry the 1
0+0+1=1 so we write down the 1
These are carried over values from the previous column
answer
Carried over
Another example of adding binary
Add 101 and 1001 in binary
1
0
1
1
0
0
1
1
1
1
0
answer
1
Carry over
To explain:
1+1 in binary is 10 so carry 1 and place zero
In next column we carried 1 so it will be 0+0+1=1
In next column 1+0 no carry over so 1
In next column 1 so 1 is displayed
Last binary addition
Add 11000010 and 10111010
1
1
1
0
0
0
1
0
1
0
1
1
0
1
0
0
1
1
1
1
0
0
1
In this case when we add these numbers together we find that we need a ninth column.If
our computer only had 8 bits to store numbers this would mean that the carry over from
the 8th column would be lost.
THIS IS CALLED THE OVERFLOW. The calculation has overflowed the available space.
In 8 bits the largest number we can store is 255
Hexamdecimal
The reason for using hexadecimal is that large binary numbers are
difficult to remember and when programmers work with these values
they need something that is easier to recognise and appreciate.
Since a byte has 8 bits each it easily splits into 2 sections known as
nibbles that are 4 bits
If we look at our column headings for base 2 you will note that the first
4 are
8
4
2
1
0
0
0
0
=0
8
4
2
1
1
1
1
1
=15
Hexadecimal continued….
If you recall in base 10 we have the 10 symbols 0-9
If we use the 16 sybols for 0-15 we can use a
system based upon place values of 16 rather than
2 or 10.This is called hexdecimal(hex)
Thre is a need though for symbols for the numbers
10,11,12,13,14,15 because in base 16, 12 would
mean 1 lot of 16 and 2 lots of 1(or 18)
Hexadecimal
Converting binary to hexadecimal:
11110011 into hex:
NIBBLE 1(4 BITS)
NIBBLE 2(4 BITS)
8
4
2
1
8
4
2
1
1
1
1
1
0
0
1
1
Split the 8 bits into two nibbles:
1111
0011
Put into the column headings:
Add the column headings together:
In hexadecimal this becomes:
3F
15
3
ANSWER
FIND 3 ON
HEX SCALE
THEN FIND
15 ON HEX
SCALE
THEN ADD
Converting denary to hexadecimal:
45 denary into hex:
Divide the number by 16 repeatedly and note the remainder
45
/16
=2
Remainder
13 = D
2
/16
=0
Remainder
2
The number is placed before the letter so 45 is converted to 2D
:
Converting hexadecimal into binary:
NB:TO WORK THIS OUT YOU NEED TO FIRST WORK OUT THE BINARY EQUIVALENT OF
EACH PART OF THE HEX NUMBER –IE TRANSLATE 3 IN HEX TO BINARY THEN B IN HEX
TO BINARY USING TABEL THEN FIND B IN BINARY
3B hex into binary:
3 in binary = 0011
128
0
64
0
32
0
16
0
8
0
4
0
2
1
NIBBLE 1
1
1
HEX B = 11 = 1011
128
64
32
16
8
4
2
1
0
0
0
0
1
0
1
1
HALF THE 8 BITS INTO 4 BITS Put the two nibbles together to get a byte
and this gives 111011
8
0
4
0
2
1
1
1
8
4
2
1
1
0
1
1
NB: you do not need to include any 0s at the beginning
so 00111011 is the same as 111011
NIBBLE 2
NOW YOUR TURN !!!
Convert 28, 72, 131, 235 and 255 from denary to binary
Convert 1011, 11011, 10001010 and 11001000 to denary
How many kilobytes are there in a gigabyte?
Add the following numbers in binary and show your working:
1010 + 101
10001 + 11001
111001 + 100011
Convert the following binary numbers into hexadecimal:
10010011 b) 10101000
c) 111011
Convert the following hexadecimal numbers into binary AND denary:
1A
b) 35
c) BC
REMEMBER REFER BACK TO THE HEXADECIMAL TABLE TO WORK OUT THE