Binary Numbers Brian Borucki –

advertisement
Binary Numbers
Brian Borucki – bborucki@bu.edu

Review of binary and bits
◦ Number representation
◦ Converting from binary to decimal
◦ Converting from decimal to binary
◦ Sizes of data

Work on Discussion Problems



Digital electronics are always in one of two states,
on or off
So deep down inside your phone, all it really is, is a
bunch of these:
So if this is all we have to work with, how do we
store information?

We can represent these switches as ‘bits’

1
0
1
A ‘bit’ is either a 1 or 0 and is the smallest
unit of information a computer can hold
◦ Represents: on/off, exists/non-existent, true/false

We can represent numbers many different
ways
◦ 4,321 , π , 𝑒 𝑖π , 0xFACE , 10101

We can also change from one representation
to another, say base 10:
◦ 4,321, 3.1415…. , -1, 64206 , 21

When do you move to the next decimal place?
◦ When you’ve exceeded the number of possible
integers (0 -> 9)
𝟏𝟎𝟏
1
𝟏𝟎𝟎
𝟏𝟎𝟏
𝟏𝟎𝟎
1
9
1
2
9
2
3
9
3
...
…
...
7
9
7
8
9
8
9
9
9
0
0
0
𝟏𝟎𝟐
1

It works exactly the same way in binary
◦ The only difference is you only have 2 numbers to
work with, 0 and 1
𝟐 𝟑 𝟐𝟐 𝟐𝟏 𝟐𝟎
0
1
1
1
0
1
1
1
0
0
1
0
1
1
1
0
1
1
1
0
0
0



Given any number we can break it down
according to it’s base, such as 3,857 10
3,857 = 3000 + 800 + 50 + 7
3x𝟏𝟎𝟑
8x𝟏𝟎𝟐
5x𝟏𝟎𝟏
7x𝟏𝟎𝟎
3
8
5
7
Number = 𝑉𝑎𝑙𝑢𝑒 𝑥 𝐵𝑎𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑜𝑛 summed over
all positions

Bi – meaning two, gives us ‘binary’
◦ Two possible states: on or off




We can find the base 10 equivalent of 10112
1x𝟐𝟑
0x𝟐𝟐
1x𝟐𝟏
1x𝟐𝟎
1
0
1
1
(1 x 8) + (0 x 4) + (1 x 2) + (1 x 1)
8+0+2+1
1110


We’ve seen how to convert from base 2 to 10
What about the other way around?
◦ Convert 13 to binary:
𝟐𝟒 = 16
𝟐𝟑 = 8
𝟐𝟐 = 4
𝟐𝟏 = 2
𝟐𝟎 = 1
?
?
?
?
?
◦ Remainder : 13
 Does 16 go into 13?
 No, put a 0


We’ve seen how to convert from base 2 to 10
What about the other way around?
◦ Convert 13 to binary:
𝟐𝟒 = 16
𝟐𝟑 = 8
𝟐𝟐 = 4
𝟐𝟏 = 2
𝟐𝟎 = 1
0
?
?
?
?
◦ Remainder : 13
 Does 8 go into 13?
 Yes, put a 1
 New remainder becomes 13 - 8 = 5


We’ve seen how to convert from base 2 to 10
What about the other way around?
◦ Convert 13 to binary:
𝟐𝟒 = 16
𝟐𝟑 = 8
𝟐𝟐 = 4
𝟐𝟏 = 2
𝟐𝟎 = 1
0
1
?
?
?
◦ Remainder : 5
 Does 4 go into 5?
 Yes, put a 1
 New remainder becomes 5 - 4 = 1


We’ve seen how to convert from base 2 to 10
What about the other way around?
◦ Convert 13 to binary:
𝟐𝟒 = 16
𝟐𝟑 = 8
𝟐𝟐 = 4
𝟐𝟏 = 2
𝟐𝟎 = 1
0
1
1
?
?
◦ Remainder : 1
 Does 2 go into 1?
 No, put a 0


We’ve seen how to convert from base 2 to 10
What about the other way around?
◦ Convert 13 to binary:
𝟐𝟒 = 16
𝟐𝟑 = 8
𝟐𝟐 = 4
𝟐𝟏 = 2
𝟐𝟎 = 1
0
1
1
0
?
◦ Remainder : 1
 Does 1 go into 1?
 Yes, put a 1
 New remainder becomes 1-1 = 0


We’ve seen how to convert from base 2 to 10
What about the other way around?
◦ Convert 13 to binary:
𝟐𝟒 = 16
𝟐𝟑 = 8
𝟐𝟐 = 4
𝟐𝟏 = 2
𝟐𝟎 = 1
0
1
1
0
1
◦ Remainder : 0
 Done!
 Our final result is that 13 = 1101

A ‘byte’ is 8 bits
◦ So 4 bytes contains how many bits?

A Kilobyte is 1,000 bytes (KB)
◦ One thousand

A Megabyte is 1,000,000 bytes (MB)
◦ One million

A Gigabyte is 1,000,000,000 bytes (GB)
◦ One billion
Download