Lab #1 Follow-Up Unix Binary / Hexadecimal Python
Lab #1 Follow-Up Unix Binary / Hexadecimal Python
Media Access Control (MAC) address
B4-D8-A
DecimalHex(adecimal) A 11B 12C 13D 14E 15F
B 4 DecimalHex(adecimal) A 11B 12C 13D 14E 15F
B 4 DecimalHex(adecimal) A 11B 12C 13D 14E 15F 11×16 + 4×1
B 4 DecimalHex(adecimal) A 11B 12C 13D 14E 15F 11× ×16 0
B 4 DecimalHex(adecimal) A 11B 12C 13D 14E 15F 11×16 + 4×1
B 4 DecimalHex(adecimal) A 11B 12C 13D 14E 15F 11×16 + 4×
B 4 DecimalHex(adecimal) A 11B 12C 13D 14E 15F 11×16 + 4×
All modern numbering systems work this way B 4 11× × ×16 + 4× × × × × ×10 + 0×1 180
Why Base 16?
DecimalHexBinary A B C D E F1111
Why Base 16? DecimalHexBinary A B C D E F1111
B 4 Eight Bits = One Byte DecimalHexBinary A B C D E F
Why Base Two?
ENIAC (1946)
1940s Faster, Cheaper, Smaller 1950s 1960s Today Vacuum tube RelayTransistor Integrated Circuits
● To convert from binary to decimal Start from right Multiply 0,1 by powers of two (1, 2, 4, 8, …) Sum of these products is decimal equivalent ● E.g., = ??? 10 Binary-to-Decimal Conversion
● To convert from binary to decimal Start from right Multiply 0,1 by powers of two (1, 2, 4, 8, …) Sum of these products is decimal equivalent ● E.g., = ??? 10 1 * 2 0 = 1 Binary-to-Decimal Conversion
● To convert from binary to decimal Start from right Multiply 0,1 by powers of two (1, 2, 4, 8, …) Sum of these products is decimal equivalent ● E.g., = ??? 10 1 * 2 0 = 1 +0 * 2 1 = 0
Binary-to-Decimal Conversion ● To convert from binary to decimal Start from right Multiply 0,1 by powers of two (1, 2, 4, 8, …) Sum of these products is decimal equivalent ● E.g., = ??? 10 1 * 2 0 = 1 +0 * 2 1 = 0 +1 * 2 2 = 4
Binary-to-Decimal Conversion ● To convert from binary to decimal Start from right Multiply 0,1 by powers of two (1, 2, 4, 8, …) Sum of these products is decimal equivalent ● E.g., = ??? 10 1 * 2 0 = 1 +0 * 2 1 = 0 +1 * 2 2 = 4 +1 * 2 3 = 8
Binary-to-Decimal Conversion ● To convert from binary to decimal Start from right Multiply 0,1 by powers of two (1, 2, 4, 8, …) Sum of these products is decimal equivalent ● E.g., = * 2 0 = 1 +0 * 2 1 = 0 +1 * 2 2 = 4 +1 * 2 3 = 8 ____________ 13
13r 2 = 1 13 ÷ 2 = 6 6r 2 = 0 6 ÷ 2 = 3 3r 2 = 1 3 ÷ 2 = 1 1r 2 = 1 1 ÷ 2 = 0 ___________ Decimal-to-Binary Conversion To convert from decimal to binary 1.Take remainder of decimal number / 2 2.Write down remainder right-to-left 3.If decimal number is zero, we’re done 4.Divide decimal number by 2 5.Go to step 1.
Fractions = ???? 2
Fractions × × ×10 -2
Fractions = 3× × × × × × ×2 -2
Problem! = ???? 2
Google patriot missile failure for a real-world example
What about text? ASCII: One byte per character
What about text? Unicode: (Up to) two bytes per character
Numbers or text? Each application (MS Word, Excel) expects either (ASCII) text or (“raw binary”) numbers Try opening a an Excel spreadsheet in WordPad!