1 / 22

Binary / Hex

Binary / Hex. Binary and Hex The number systems of Computer Science. Number Systems in Main Memory. The on and off states of the capacitors in RAM can be thought of as the values 1 and 0, respectively.

saburo
Download Presentation

Binary / Hex

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Binary / Hex Binary and Hex The number systems of Computer Science

  2. Number Systems in Main Memory • The on and off states of the capacitors in RAM can be thought of as the values 1 and 0, respectively. • Therefore, thinking about how information is stored in RAM requires knowledge of the binary (base 2) number system. • Let’s review the decimal (base 10) number system first.

  3. The Decimal Numbering System • The decimal numbering system is a positional number system. • Example: • 5 6 2 1 1 X 100 = 1 • 103 102 101 100 2 X 101 = 20 • 6 X 102 = 600 • 5 X 103 = 5000

  4. 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.

  5. The Binary Number System • The binary numbering system is also known as 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.

  6. The Binary Number System (con’t) • The Binary Number System is also a positional numbering system. • Instead of using ten digits, 0 - 9, the binary system uses only two digits, 0 and 1. • Example of a binary number and the values of the positions: • 1000001 • 26 25 24 23 22 21 20

  7. Converting from Binary to Decimal • 1001101 1 X 20 = 1 • 26 25 24 23 22 21 20 0 X 21 = 0 • 1 X 22 = 4 • 20 = 1 24 = 16 1 X 23 = 8 • 21 = 225 = 320 X 24 = 0 • 22 = 426 = 640 X 25 = 0 • 23 = 81 X 26 = 64 77

  8. Converting from Binary to Decimal (con’t) Practice conversions: BinaryDecimal 11101 1010101 100111

  9. Converting Decimal to Binary • First make a list of the values of 2 to the powers of 0 to the number being converted - e.g: • 20 = 1, 22 = 4, 23 = 8, 24 = 16, 25 = 32, 26 = 64,… • Perform successive divisions by 2, placing the remainder of 0 or 1 in each of the positions from right to left. Continue until the quotient is zero; e.g.: 4210 25 24 23 22 21 20 • 32 16 8 4 2 1 • 101010 • alternative method: “subtract maximum powers and repeat”. E.g.: • 42 - 32 = 10 - 8 = 2 - 2 = 0 • 25 24 23 22 21 2 • 101010

  10. Converting From Decimal to Binary (con’t) Practice conversions: DecimalBinary 59 82 175

  11. Counting in Binary • Binary • 0 • 1 • 10 • 11 • 100 • 101 • 110 • 111 • Decimal equivalent • 0 • 1 • 2 • 3 • 4 • 5 • 6 • 7

  12. 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

  13. 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

  14. 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 - there are too many digits to deal with. We will make errors. • Memory addresses and other data can be quite large. Therefore, we sometimes use the hexadecimal number system (shorthand for binary that’s easier for us to work with)

  15. The Hexadecimal Number System • The hexadecimal number system is also known as base 16. The values of the positions are calculated by taking 16 to some power. • Why is the base 16 for hexadecimal numbers ? • Because we use 16 symbols, the digits 0 and 1 and the letters A through F.

  16. The Hexadecimal Number System (con’t) BinaryDecimalHexadecimalBinaryDecimalHexadecimal 0 0 0 1010 10 A 1 1 1 1011 11 B 10 2 2 1100 12 C 11 3 3 1101 13 D 100 4 4 1110 14 E 101 5 5 1111 15 F 110 6 6 111 7 7 1000 8 8 1001 9 9

  17. The Hexadecimal Number System (con’t) • Example of a hexadecimal number and the values of the positions: • 3C8B051 • 166 165 164 163 162 161 160

  18. Binary to Hexadecimal Conversion • Binary 0 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 • Hex 5 0 9 7 • Written: 509716

  19. 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.

  20. 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

  21. Summary of Number Systems • 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 F: 0 1 2 3 4 5 6 7 8 9 A B C D E F)

  22. Example of Equivalent Numbers • Binary: 1 0 1 0 0 0 0 1 0 1 0 0 1 1 12 • Decimal: 2064710 • Hexadecimal: 50A716 • Notice how the number of digits gets smaller as the base increases.

More Related