170 likes | 461 Views
Binary / Hex. Binary and Hex The number systems of Computer Science. Main Memory. Capacitors on/off translates to values 1/0 requires use of Binary number system Investigate Decimal number system first. The Decimal Numbering System.
E N D
Binary / Hex Binary and Hex The number systems of Computer Science
Main Memory • Capacitors on/off translates to values 1/0 • requires use of Binary number system • Investigate Decimal number system first
The Decimal Numbering System • The decimal numbering system is a positional number system. • Example: • 5 6 2 1 1 X 100 • 1000 100 10 1 2 X 101 • 6 X 102 • 5 X 103
What is the base ? • The decimal numbering system is also known as base 10. The values of the positions are calculated by taking 10 to some power. • Why is the base 10 for decimal numbers ? • Because we use 10 digits. The digits 0 through 9.
What is the base ? • The binary numbering system is called binary because it uses base 2. The values of the positions are calculated by taking 2 to some power. • Why is the base 2 for binary numbers ? • Because we use 2 digits. The digits 0 and 1.
The Binary Numbering System • The Binary Numbering System is also a positional numbering system. • Instead of using ten digits, 0 - 9, the binary system uses only two digits, the 0 and the 1. • Example of a binary number & the values of the positions. • 1000001 • 26 25 24 23 22 21 20
Computing the Decimal Valuesof Binary Numbers • 1000001 1 X 20 = 1 • 26 25 24 23 22 21 20 0 X 21 = 0 • 0 X 22 = 0 • 20 = 1 24 = 16 0 X 23 = 0 • 21 = 225 = 320 X 24 = 0 • 22 = 426 = 640 X 25 = 0 • 23 = 81 X 26 = 6465
Converting Decimal to Binary • First make a list of the values of 2 to the powers of 0 to 8, then use the subtraction method. • 20 = 1, 21 = 2, 22 = 4, 23 = 8, 24 = 16, • 25 = 32, 26 = 64, 27 = 128, 28 = 256 • Example: 42 42 10 2 • - 32 - 8 - 2 • 101010 • 25 24 23 22 21 20
Counting in Binary • Binary • 0 • 1 • 10 • 11 • 100 • 101 • 110 • 111 • Decimal equivalent • 0 • 1 • 2 • 3 • 4 • 5 • 6 • 7
Addition of Binary Numbers • Examples: • 1 0 0 1 0 0 0 1 1 1 0 0 • + 0 1 1 0 + 1 0 0 1 + 0 1 0 1 • 1 1 1 1 1 0 1 0 1 0 0 0 1
Addition of Large Binary Numbers • Example showing larger numbers: • 1 0 1 0 0 0 1 1 1 0 1 1 0 0 0 1 • + 0 1 1 1 0 1 0 0 0 0 0 1 1 0 0 1 • 1 0 0 0 1 0 1 1 1 1 1 0 0 1 0 1 0
Working with large numbers • 0 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 • Humans can’t work well with binary numbers. We will make errors. • Shorthand for binary that’s easier for us to work with - Hexadecimal
Hexadecimal • Binary 0 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 • Hex 5 0 9 7 • Written: 509716
What is Hexadecimal really ? • Binary 0 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 • Hex 5 0 9 7 • A number expressed in base 16. It’s easy to convert binary to hex and hex to binary because 16 is 24.
Hexadecimal • Binary is base 2, because we use two digits, 0 and 1 • Decimal is base 10, because we use ten digits, 0 through 9. • Hexadecimal is base 16. How many digits do we need to express numbers in hex ? 16 (0 through ?) • 0 1 2 3 4 5 6 7 8 9 A B C D E F
Counting in Hex • Binary Hex Binary Hex • 0 0 0 0 0 1 0 0 0 8 • 0 0 0 1 1 1 0 0 1 9 • 0 0 1 0 2 1 0 1 0 A • 0 0 1 1 3 1 0 1 1 B • 0 1 0 0 4 1 1 0 0 C • 0 1 0 1 5 1 1 0 1 D • 0 1 1 0 6 1 1 1 0 E • 0 1 1 1 7 1 1 1 1 F
Another Binary to Hex Conversion • Binary 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 • Hex 7 C 3 F • 7C3F16