Download Number Systems Decimal aka Base 10 Binary aka Base 2 Binary

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Ethnomathematics wikipedia , lookup

Infinitesimal wikipedia , lookup

History of logarithms wikipedia , lookup

Mathematics of radio engineering wikipedia , lookup

Large numbers wikipedia , lookup

Elementary arithmetic wikipedia , lookup

Arithmetic wikipedia , lookup

Approximations of π wikipedia , lookup

Elementary mathematics wikipedia , lookup

Location arithmetic wikipedia , lookup

Addition wikipedia , lookup

Positional notation wikipedia , lookup

Transcript
Number Systems
• Most of us are used to dealing with the decimal system.
• In decimal we have 10 unique digits {0,1,2,3,4,5,6,7,8,9}
• Digital computers are made up of electronic circuits, which
have exactly 2 states: on and off.
• Computers use a numbering system which has exactly 2
symbols, representing on and off. This is known as a binary
numbering system.
• In binary we have 2 unique digits {0,1}
Decimal aka Base 10
• Once we get to 9 in decimal, we start combining digits to
create 2 digit numbers that go from 10..99.
• Once we get to 99 we need to use 3 digit numbers, such as
100..999 etc.
• When we have a number such as 4913 what does it actually
mean?
I
I
I
• binary digits are also called bits.
Why is it different from 9413 or 1349 which contain the same
digits?
The positions of the digits are very important
The number 4913 actually means
I
I
4000 + 900 + 10 + 3 which is the same as
4 ∗ 103 + 9 ∗ 102 + 1 ∗ 101 + 3 ∗ 100
1
2
Binary aka Base 2
Binary aka Base 2
Decimal
0
1
2
3
4
5
6
7
• Since we can only use 0 and 1, once we get to 1 in binary, we
start combining bits to create 2 bit numbers then 3 bit
numbers, then 4 bit numbers etc.
• When we have 8 bits we call it a byte!
• The number 1011 actually means
I
I
1 ∗ 23 + 0 ∗ 22 + 1 ∗ 21 + 1 ∗ 20
8 + 2 + 1 = 11
• There are 10 different types of people. Those who understand
binary and those that don’t.
• What is the largest number you can represent in 4 bits?
Decimal
8
9
10
11
12
13
14
15
Binary
1000
1001
1010
1011
1100
1101
1110
1111
• so 4 bits can represent 16 different numbers from 0..15
• what about in a byte (8 bits)? Is there a pattern to help us ?
I
I
3
Binary
0
1
10
11
100
101
110
111
4 bits represents 24 different numbers from 0..24 - 1
8 bits represents 28 different numbers from 0..28 - 1
4
Hexadecimal aka Base 16
• Binary numbers are not easy for humans to read or type
correctly.
• We can map 4 bits to 1 hexadecimal digit which is more
readable for humans.
• In hexadecimal we have 16 unique digits
{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
I
So A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.
• Once we get up to F we need 2 digits numbers, when we get
to FF, we need 3 digit numbers etc
• We use the prefix 0x to make it clear we are treating our
number as hexadecimal (not decimal). eg
I
I
0x8FA1
0x1021 which is very different from 1021
Hexadecimal aka Base 16
• The number 0x8FA1 actually means
I
I
8 ∗ 163 + 15 ∗ 162 + 10 ∗ 161 + 1 ∗ 160
32768 + 3840 + 160 + 1 = 36769
• To convert 0x8FA1 to binary just convert each hexadecimal to
4 bit binary numbers and join them together eg
8
F
A
1
1000 1111 1010 0001
• You can do the same in reverse to convert from binary to
hexadecimal
• How do you think Octal aka Base 8 works?
5
6
Converting from Decimal to other Bases
Binary and Negative Numers
• While (the quotient is not zero)
• Divide the decimal number by the new base
• Make the remainder the next digit to the left in the answer
• Replace the original decimal number with the quotient
• Suppose we are working with 4 bit numbers where we can
represent 16 different numbers.
I
I
• To convert 13 to binary
I
I
I
I
I
13/2 = 6 remainder 1 (this will be the right most bit)
6/2 = 3 remainder 0
3/2 = 1 remainder 1
1/2 = 0 remainder 1 (this will be the left most bit)
Answer: 1101
If we only need positive numbers we can represent 0..15.
If we want to represent negative numbers too, then we need to
reduce the range of positive numbers we can represent so some
of our bit combinations can represent negative numbers.
• On computer systems when we want to be able to represent
negative numbers we use a binary format called 2’s
complement.
You can convert to hexadecimal by dividing by 16. Try converting
100 to hexadecimal yourself!
7
8
Exercise
Binary and Negative Numers
What happens if we add 1 and -1?
Decimal
0
1
2
3
4
5
6
7
Binary
0000
0001
0010
0011
0100
0101
0110
0111
Decimal
-8
-7
-6
-5
-4
-3
-2
-1
Binary
1000
1001
1010
1011
1100
1101
1110
1111
• Now with 4 bits we have 23 -1 positive numbers 23 negative
numbers and 0.
• All negative numbers start with a 1
• To negate a number just reverse all 0’s and 1’s and add 1.
I
0101 (5) with bits reversed is 1010 then add 1 and you get
1011 (-5)
9
1111 +
0001
0000 = 0
What happens if we add 1 to 7?
0111 +
0001
1000 = -8
Overflow!
Try adding -1 to -8
1111 +
1000
0111 = 7
Overflow!
10