Computers and Math
Binary, Hex, and Decimal Oh My
Copyright © Texas Education Agency, 2015. All rights reserved.
1
BACK TO THE FOUNDATION
A brief review of decimal notation
Copyright © Texas Education Agency, 2015. All rights reserved.
2
Numbers Review
a. Natural numbers
b. Integers
c. Positional numbering system
d. Number base
Copyright © Texas Education Agency, 2015. All rights reserved.
3
Exponents
Any number to the 0 power = 1
Example: 20 = 1
Any number to the 1st power = that number
Example: 21 = 2
Copyright © Texas Education Agency, 2015. All rights reserved.
4
Decimals
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
5
7 * 102 = 7 * 100 = + 700
2 * 101 = 4 * 10 = + 20
5 * 100 = 5 * 1
=+ 5
725
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
6
CONVERTING FROM BINARY
TO DECIMAL
Copyright © Texas Education Agency, 2015. All rights reserved.
7
Binary
• Base 2
• Uses 0 and 1
Copyright © Texas Education Agency, 2015. All rights reserved.
8
Binary Table
Place holder value
This is where binary digits (0s and 1s) go
27
128
26
64
25
32
24
16
23
8
22
4
21
2
20
1
Decimal equivalent
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
9
Convert 000011102
from binary to decimal
0
0
0
0
1
1
1
0
27
26
25
24
23
22
21
20
128 64
32
16
8
4
2
0
000011102 = 1410
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
128 * 0 = 0
64 * 0 = 0
32 * 0 = 0
16 * 0 = 0
8*1=8
4*1=4
2*1=2
1*0=0+
14
10
YOUR TURN
Copyright © Texas Education Agency, 2015. All rights reserved.
11
CONVERTING FROM DECIMAL
TO BINARY
Copyright © Texas Education Agency, 2015. All rights reserved.
12
Binary Conversion
Can be done two different ways
– Long division
– Subtraction
Copyright © Texas Education Agency, 2015. All rights reserved.
13
Long Division
Convert 3510 to binary
2
17
35
2
15
14
8
2 17
16
1
2
4
8
8
0
2
2
4
4
0
2
1
2
2
0
2
0
1
0
2
1
0
0
0
0
Binary bits
1
01000112 = 3510
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
14
Subtraction
Convert 3710 from decimal to binary
37 - 32 = 3
3–2=1
1–1=0
27
26
25
24
23
22
21
20
128 64
32
16
8
4
2
1
1
1
1
3710 = 001000112
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
15
YOUR TURN
Copyright © Texas Education Agency, 2015. All rights reserved.
16
HEXADECIMAL BASE 16
Copyright © Texas Education Agency, 2015. All rights reserved.
17
Hexadecimal
Characters
– 0–9
– A–F
Can convert directly from hex to decimal but not
from decimal to hex
Copyright © Texas Education Agency, 2015. All rights reserved.
18
Hexadecimal
(Hex)
Binary
Decimal
1
0001
1
2
0010
2
3
0011
3
4
0100
4
5
0101
5
6
0110
6
7
0111
7
8
1000
8
9
1001
9
A
1010
10
B
1011
11
C
1100
12
D
1101
13
E
1110
14
F
1111
15
Copyright © Texas Education Agency, 2015. All rights reserved.
Used with permission: Robyn Segrest May 12, 2015.
19
Hexadecimal Table
Place holder value
This is where hexadecimal characters (0 - F) would go
165
164 163 162
1048576 65536 4096 256
161
16
160
1
Decimal equivalent
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
20
Convert FF16 from to decimal
F
163
162
F
161 160
65536 4096 16
15 * 16 = 240
15 * 1 = +15
255
1
FF16 = 25510
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
21
YOUR TURN
Copyright © Texas Education Agency, 2015. All rights reserved.
22
DECIMAL TO HEX
CONVERSION
Copyright © Texas Education Agency, 2015. All rights reserved.
23
Convert 5410 to Hexadecimal
Convert from
decimal to binary
Convert from
binary to hex
54- 32
22 – 16
6–4
2–2
0011
3
= 22
= 6
= 2
= 0
5410 = 0011 01102
0110
6
5410 = 3616
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
24
Convert 12810 to Hexadecimal
128 - 128 = 0
12810 = 1000 00002
1000
8
Binary to
hex
Decimal
to binary
0000
0
12810 = 8016
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
25
YOUR TURN
Copyright © Texas Education Agency, 2015. All rights reserved.
26
IP ADDRESSING
Copyright © Texas Education Agency, 2015. All rights reserved.
27
IPv4
Every node on a network must have a unique IP
address: Internet Protocol version 4
• Unique 32-bit number
– Divided into four octets divided by decimal points
» EX: 192.168.0.3
• Separated into classes
Copyright © Texas Education Agency, 2015. All rights reserved.
28
Commonly Used IPv4 Classes
Number of
Networks
Maximum
Addressable
Hosts
Class
First Octet
Shared
Octets
A
1 – 126
1
126
16,777,214
B
128 – 191
2
> 16,000
65,534
C
192 – 223
3
> 2,000,000
254
Used with permission: Robyn Segrest March 29, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
29
IPv4
Highest decimal number an octet may be is 255
– Each octet is equal to eight binary bits
• 111111112 = 25510
Running out of IPv4 addresses due to 32-bit limitation
Combined with a ‘subnet mask’ to increase number of
addressable nodes on a network
Copyright © Texas Education Agency, 2015. All rights reserved.
30
Subnet Mask
Class
First Octet
Default Subnet
Mask
A
1 – 126
255.0.0.0
B
128 – 191
255.255.0.0
C
192 – 223
255.255.255.0
Used with permission: Robyn Segrest March 29, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
31
IPv6
Composed of 128 bits
– Eight 16-bit fields
• Represented by hexadecimal numbers
– Divided into groups of four hexadecimal characters
» EX: FEE3:00FF:003D:0000:0000:0000:3015:AABC
– Multiple fields with zero values can be abbreviated
» EX: 00EE – EE
» 0000 - 0
Copyright © Texas Education Agency, 2015. All rights reserved.
32
Assigning IP Addresses
Can be done manually or by DHCP (Dynamic Host
Configuration Protocol)
– Static IP address
• Manually assigned
• Does not change
• Human error in duplicating addresses can cause connection
issues
– Dynamic IP addressing
• Assigned automatically by a DHCP server
• Most common and simplest method
Copyright © Texas Education Agency, 2015. All rights reserved.
33
Boolean Operators
Also called Logical Operators or just bool
Logical operators that return true or false
Three basic Boolean operators
Order of Boolean operations
Copyright © Texas Education Agency, 2015. All rights reserved.
34
Truth Tables
AND
OR
Input 1
Input 2
Output
Input 1
Input 2
Output
0
0
0
0
0
0
0
1
0
0
1
1
1
0
0
1
0
1
1
1
1
1
1
1
!AND
!OR
Input 1
Input 2
Output
Input 1
Input 2
Output
0
0
1
0
0
1
0
1
1
0
1
0
1
0
1
1
0
0
1
1
0
1
1
0
Used with permission: Robyn Segrest May 12, 2015.
Copyright © Texas Education Agency, 2015. All rights reserved.
35
ANDING
Every IP address has a default subnet mask
– Class A – 255.0.0.0
– Class B – 255.255.0.0
– Class C – 255.255.255.0
In order to locate a specific node on the network a
computer must AND the IP address with the appropriate
subnet mask in binary
Based on our truth tables we should know the following
–
–
–
–
1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0
Copyright © Texas Education Agency, 2015. All rights reserved.
36
Finding the Network Address
EXAMPLE:
• IP address: 192.168.0.10
• Subnet mask: 255.255.255.0
First we convert both to binary:
IP address: 11000000.10101000.00000000.00001010 (192.168.0.10)
Subnet Mask: 11111111.11111111.11111111.00000000 (255.255.255.0)
AND: 11000000.10101000.00000000.00000000 (192.168.0.0)
The result of ANDing is the network address.
Copyright © Texas Education Agency, 2015. All rights reserved.
37
YOUR TURN
Copyright © Texas Education Agency, 2015. All rights reserved.
38