Pathway Introduction: Information Technology

Download Report

Transcript Pathway Introduction: Information Technology

Number Systems &
Binary
How to count
How do we represent numbers?
• Early systems:
– Actual count : ||||| = 5
– Roman numers : XI = 11
• Hard to do math:
MCXXIII + CLXXIV = ????
Place Value Systems
• What we are used to
– Digits that have different meaning based on place:
ten
thousands
thousands
hundreds
tens
ones
1
2
0
5
9
= 1 * 10000 + 2 * 1000 + 0 * 100 + 5 * 10 + 9 * 1
= 12059
Decimal Numbers
• Base 10 : Each place increases by a power of 10
ten
thousands
104
thousands
103
hundreds
102
tens
101
ones
100
1
2
0
5
9
Why Base 10?
• Only one thing special about base 10:
• Other systems have been used:
– Mayans : Base 20
– Babylonians : Base 60
Other Bases
• Base determines the multiplier from one
column to next
• Base 20
160thousands
204
eightthousands
203
fourhundreds
202
twentys
201
ones
200
1
2
0
5
9
= 1 * 160000 + 2 * 8000 + 0 * 400 + 5 * 20 + 9 * 1
= 176109
Other Bases
• Base also determines how many digits
needed:
• Base 10 : 10 digits : 0-9
• Base 2 : 2 digits : 0-1
• Base 8 : 8 digits : 0-7
Base 2
• Base two
– Only 1 and 0
– Places are powers of 2
thirty-twos
25
sixteens
24
eights
23
fours
22
twos
21
ones
20
1
0
1
1
0
1
= 1 * 32 + 0 * 16 + 1 * 8 + 1 * 4 + 0 * 2 + 1 * 1
= 32 + 8 + 4 + 1
= 45
Notation
• Subscript used to indicate base:
1012  101 in base 2 (numeric value of 5)
10110  101 in base 10 (numeric value of 101)
More digits = bigger numbers
• 4 digits we can represent values 0-15
15:
8
4
2
1
1
1
1
1
• 8 digits can represent 0-255
• 16 digits can represent 0-65535
• n digits can represent 0 to (2n-1)
Leading 0's
• Leading 0's do not matter:
128
64
32
16
8
4
2
1
0
0
0
0
0
1
0
1
101 = 0101 = 00000101
Leading 0's
• Leading 0's do not matter:
128
64
32
16
8
4
2
1
0
0
0
0
0
1
0
1
101 = 0101 = 00000101
• Byte : fundamental storage unit : 8 bits
– Often write binary numbers in multiples 8 bits
Counting to ten in binary
• In binary you generally show leading 0's
• Values for 1-10 (decimal) in binary:
1
0001
6
0110
2
0010
7
0111
3
0011
8
1000
4
0100
9
1001
5
0101
10
1010
Binary -> Decimal with Table
1.
Make a table like this one
128
2.
3.
64
32
16
8
4
2
1
Write in the binary number
128
64
32
16
8
4
2
1
0
1
1
0
0
1
0
1
Add up all the numbers from the top that have a 1 under them:
64 + 32 + 4 + 1 = 101
Decimal -> Binary with Table
Make a table like this one
1.
128
2.
•
64
32
16
8
4
2
Say we are converting 83:
Look for largest number that is smaller than our value
1
Decimal -> Binary with Table
Make a table like this one
1.
2.
•
•
•
128
64
0
1
32
16
8
4
2
Say we are converting 83:
Look for largest number that is smaller than our value
We have 1 of those (0 of anything bigger)
Subtract that from our number
83 – 64 = still have 19 to make
1
Decimal -> Binary with Table
Make a table like this one
1.
2.
•
•
•
•
128
64
32
16
0
1
0
1
8
4
2
Say we are converting 83:
Look for largest number that is smaller than our value
We have 1 of those (0 of anything bigger)
Subtract that from our number
83 – 64 = still have 19 to make
Look for largest value smaller than that…
Now have 19 – 16 = 3 left
1
Decimal -> Binary with Table
Make a table like this one
1.
2.
•
•
•
•
•
128
64
32
16
8
4
2
0
1
0
1
0
0
1
Say we are converting 83:
Look for largest number that is smaller than our value
We have 1 of those (0 of anything bigger)
Subtract that from our number
83 – 64 = still have 19 to make
Look for largest value smaller than that…
Now have 19 – 16 = 3 left
Continue… need a 2, have one left…
1
Decimal -> Binary with Table
1.
2.
Make a table like this one
128
64
32
16
8
4
2
1
0
1
0
1
0
0
1
1
Say we are converting 83:
0101 0011 means 64 + 16 + 2 + 1 = 83
Conversion With Division/
Multiplication
• Binary works in powers of 2
• Multiplying/dividing by 2 shifts digits
Decimal -> Binary with Division
•
Step 1: Start with a blank
answer and the number your
are converting
•
Step 2: Divide your number by 2
to make a quotient and a
remainder
•
Step 3: Place your remainder on
the left side of your answer
•
Step 4:
If your quotient is 0, you are
done
Otherwise, make the quotient
your new number and go back
to step 2
Convert 105 to binary:
Number ÷ 2
105
Q
R
Answer
Decimal -> Binary with Division
•
Step 1: Start with a blank
answer and the number your
are converting
•
Step 2: Divide your number by 2
to make a quotient and a
remainder
•
Step 3: Place your remainder on
the left side of your answer
•
Step 4:
If your quotient is 0, you are
done
Otherwise, make the quotient
your new number and go back
to step 2
Convert 105 to binary:
Number ÷ 2
Q
R
105 ÷ 2
52
1
Answer
Decimal -> Binary with Division
•
Step 1: Start with a blank
answer and the number your
are converting
•
Step 2: Divide your number by 2
to make a quotient and a
remainder
•
Step 3: Place your remainder on
the left side of your answer
•
Step 4:
If your quotient is 0, you are
done
Otherwise, make the quotient
your new number and go back
to step 2
Convert 105 to binary:
Number ÷ 2
Q
R
105 ÷ 2
52
1
Answer
1
Decimal -> Binary with Division
•
•
Step 1: Start with a blank
answer and the number your
are converting
Step 2: Divide your number by 2
to make a quotient and a
remainder
•
Step 3: Place your remainder on
the left side of your answer
•
Step 4:
If your quotient is 0, you are
done
Otherwise, make the quotient
your new number and go back
to step 2
Convert 105 to binary:
Number ÷ 2
Q
R
105 ÷ 2
52
1
52 ÷ 2
Answer
1
Decimal -> Binary with Division
•
•
Step 1: Start with a blank
answer and the number your
are converting
Step 2: Divide your number by 2
to make a quotient and a
remainder
•
Step 3: Place your remainder on
the left side of your answer
•
Step 4:
If your quotient is 0, you are
done
Otherwise, make the quotient
your new number and go back
to step 2
Convert 105 to binary:
Number ÷ 2
Q
R
105 ÷ 2
52
1
1
52 ÷ 2
26
0
01
Answer
Decimal -> Binary with Division
•
•
Step 1: Start with a blank
answer and the number your
are converting
Step 2: Divide your number by 2
to make a quotient and a
remainder
•
Step 3: Place your remainder on
the left side of your answer
•
Step 4:
If your quotient is 0, you are
done
Otherwise, make the quotient
your new number and go back
to step 2
Convert 105 to binary:
Number ÷ 2
Q
R
105 ÷ 2
52
1
1
52 ÷ 2
26
0
01
26 ÷ 2
13
0
001
Answer
Decimal -> Binary with Division
•
•
•
•
Step 1: Start with a blank
answer and the number your
are converting
Step 2: Divide your number by 2
to make a quotient and a
remainder
Step 3: Place your remainder on
the left side of your answer
Step 4:
If your quotient is 0, you are
done
Otherwise, make the quotient
your new number and go back
to step 2
Convert 105 to binary:
Number ÷ 2
Q
R
105 ÷ 2
52
1
1
52 ÷ 2
26
0
01
26 ÷ 2
13
0
001
13 ÷ 2
6
1
1001
6÷2
3
0
01001
3÷2
1
1
101001
1÷2
0
1
1101001
Answer
Decimal -> Binary with Division
•
•
•
•
Convert 105 to binary:
Step 1: Start with a blank
answer and the number your
are converting
Step 2: Divide your number by 2
to make a quotient and a
remainder
Step 3: Place your remainder on
the left side of your answer
Number ÷ 2
Q
R
105 ÷ 2
52
1
1
52 ÷ 2
26
0
01
26 ÷ 2
13
0
001
13 ÷ 2
6
1
1001
6÷2
3
0
01001
3÷2
1
1
101001
1÷2
0
1
1101001
Step 4:
If your quotient is 0, you are
done
Otherwise, make the quotient
your new number and go back
to step 2
128
64
32
16
8
4
2
1
1
1
0
1
0
0
1
Answer
= 105
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
0*2
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
0*2+1
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
1*2
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
01
1*2+1
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
01
3
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
01
3
3*2
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
01
3
1
3*2+0
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
01
3
1
6
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
01
3
1
6
6*2
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
01
3
1
6
_
6*2+1
Binary -> Decimal with Multiplication
•
Step 1: Start with the number
your are converting and the
answer of 0
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
Convert 11012 to decimal:
Number
Answer
1101
0
101
1
01
3
1
6
_
13
Binary -> Decimal with Multiplication
•
•
Step 2:
Multiply your answer by 2
•
Step 3: Remove the leftmost
digit of number and add it to
your answer
•
Convert 11012 to decimal:
Step 1: Start with the number
your are converting and the
answer of 0
Number
1101
0
101
1
01
3
1
6
_
13
Step 4:
If number has no more digits,
you are done
Otherwise, go back to step 2
128
64
32
16
Answer
8
4
2
1
1
1
0
1
= 13