1 / 55

Chapter 3 Representing Numbers and Text in Binary

Chapter 3 Representing Numbers and Text in Binary. Information Technology in Theory By Pelin Aksoy and Laura DeNardis. Objectives. Understand the binary numbering system Mathematically convert numbers between decimal and binary Understand binary coded decimal (BCD) representation.

leo-shannon
Download Presentation

Chapter 3 Representing Numbers and Text in Binary

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. Chapter 3Representing Numbers and Text in Binary Information Technology in Theory By Pelin Aksoy and Laura DeNardis

  2. Objectives • Understand the binary numbering system • Mathematically convert numbers between decimal and binary • Understand binary coded decimal (BCD) representation Information Technology in Theory

  3. Objectives (continued) • Learn about alternative numbering systems such as octal and hexadecimal and explain their significance in information technology • Provide real-world examples of binary and hexadecimal representation in information technology • Convert alphanumeric text into binary Information Technology in Theory

  4. The Binary Numbering System • Any information can be represented in binary • Binary is a code with two symbols, 0 and 1 • To understand binary, it’s helpful to think about how the decimal system works Information Technology in Theory

  5. Think About the Decimal System Information Technology in Theory

  6. The Base 10 System Decimal digits are combined to create larger numbers 4268.25 = (4 x 103) + (2 x 102) + (6 x 101) + (8 x 100) + (2 x 10–1) + (5 x 10–2) 10 raised to the power of... 10–2 =1/(10x10)=0.01 10–1 =1/10=0.1 100 =1 101 =10 102 =10x10=100 103 =10x10x10=1000 104 =10x10x10x10=10,000 and so on... Therefore, decimal is also called the base 10 system Information Technology in Theory

  7. Base-2 System • Binary is referred to as the base-2 system • How do we count above 1? • As in the decimal system, each placeholder has its own weighting • The weightings are based on powers of 2 instead of powers of 10 • The last digit has a value of 1 and occupies the “8s place” Information Technology in Theory

  8. Base-2 System (continued) • The number 1010 is made up of four digits • The rightmost 0 occupies the “1s place” • The next digit has a value of 1 and occupies the “2s place” • The next digit has a value of 0 and occupies the “4s place” • The last digit has a value of 1 and occupies the “8s place” Information Technology in Theory

  9. Binary to Decimal Integer Conversion 1011.11 = (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20) + (1 x 2–1) + (1 x 2–2) 2 raised to the power of... 2–4 =1/(2x2x2x2)=0.0625 2–3 =1/(2x2x2)=0.125 2–2 =1/(2x2)=0.25 2–1 =1/2=0.5 20 =1 21 =2 22 =2x2=4 23 =2x2x2=8 and so on.... Information Technology in Theory

  10. Binary to Decimal Integer Conversion Information Technology in Theory

  11. Converting an 8-bit Number into Decimal Information Technology in Theory

  12. Real-World Example of Binary to Decimal Conversion • Every computing device connecting to the Internet uses a unique identifier, known as an IP (Internet Protocol) address • Addresses are either 32 or 128 bits long • An example of an address is: • 01000111001111001001100010100000 • Dotted decimal format condenses the addresses • For example 71.60.152.160 Information Technology in Theory

  13. Converting to Dotted Decimal Format • Step 1: • Break the binary address into four groups of 8 bits • Step 2: • Convert each group of 8 bits into decimal • Step 3: • Separate each of the four resulting numbers with dots Information Technology in Theory

  14. Example • Convert the following binary IP address into dotted decimal format:01000111001111001001100010100000 • Step 1: Separate the IP address into four octets • 01000111 (Octet 1) • 00111100 (Octet 2) • 10011000 (Octet 3) • 10100000 (Octet 4) Information Technology in Theory

  15. Example (continued) • Step 2: Convert each binary octet into its equivalent decimal number • 01000111 = 0+64+0+0+0+4+2+1 = 71 • 00111100 = 0+0+32+16+8+4+0+0 = 60 • 10011000 = 128+0+0+16+8+0+0+0 =152 • 10100000 = 128+0+32+0+0+0+0+0 = 160 • Step 3: Write the decimal values separated by dots • 71.60.152.160 Information Technology in Theory

  16. Decimal Integer to Binary Conversion:Some Intuitive Examples Information Technology in Theory

  17. Method 1 for Converting Decimal to Binary • Divide number by two, noting the presence or absence of a remainder, and using this information to derive the binary representation of the decimal number • Construct a table with two columns to do this • First column contains the quotient • Second column contains a decision bit to indicate the presence or absence of a remainder as a result of the division Information Technology in Theory

  18. Example Convert the number 30 to binary Information Technology in Theory

  19. Another Example Convert the number 9 to binary Information Technology in Theory

  20. Method 2 for Converting Decimal to Binary • First determine how many bits are present in the binary equivalent of the decimal number • x bits can represent 2x decimal numbers ranging from 0 to 2x-1 • A single bit can represent two values: 0 and 1 • Two bits can represent four values: 00, 01, 10, and 11, or the decimal numbers 0,1,2,3 • Three bits can represent eight values: 000, 001, 010, 011, 100, 101, 110, 111, or the decimal numbers 0 through 7 Information Technology in Theory

  21. Method 2 for Converting Decimal to Binary (continued) • As an example, representing the number 30 would require how many bits? • Four bits can represent 24 or 16 values (decimal values from 0 to 15), not enough to represent the decimal value 30 • Five bits can represent 25 or 32 values (decimal values from 0 to 31), a sufficient amount to represent the decimal value 30 • Converting the decimal number 30 results in a five-bit binary number Information Technology in Theory

  22. Converting “9” to Binary ____ ____ ____ ____ 8s place 4s place 2s place 1s place Step 1: Compare 9 to 8. Because 9 is larger than 8, place a 1 in the 8s place. Subtract 9-8 = 1. 1 ____ ____ ____ ____ 8s place 4s place 2s place 1s place Step 2: Compare the remainder 1 to 4. Because 1 is smaller than 4, place a 0 in the 4s place and continue with the remainder 1. 1 0 ____ ____ ____ ____ 8s place 2s place 1s place 4s place Step 3: Compare the remainder 1 to 2. Because 1 is smaller than 2, place a 0 in the 2s place and continue with the remainder 1. 1 0 0 ____ ____ ____ ____ 8s place 4s place 2s place 1s place Step 4: Compare the remainder 1 to 1. Because 1 is equal to 1, place a 1 in the 1s place to complete the conversion. 1 0 0 1 ____ ____ ____ ____ 8s place 4s place 2s place 1s place Information Technology in Theory

  23. Binary Coded Decimal • Binary coded decimal(BCD) is a different approach • Encodes each digit in the decimal number individually rather than converting the entire number • To convert 30 to BCD, the 3 would first be converted into binary, and then 0 would be converted into binary • Then the two binary strings would be concatenated (i.e. brought together) to represent the number 30 Information Technology in Theory

  24. Binary Coded Decimal (continued) Information Technology in Theory

  25. BCD Example Convert the decimal number 7244(10) into binary coded decimal 7 = 0111 2 = 0010 4 = 0100 4 = 0100 7244(10) = 0111001001000100(2) (BCD) Information Technology in Theory

  26. BCD Example (continued) • Convert the sequence 0001100001111001 into decimal • First break the sequence into groups of four starting from right to left: 0001 1000 0111 1001 • Then convert each group into decimal: • 0001(2) = 1(10) • 1000(2) = 8(10) • 0111(2) = 7(10) • 1001(2) = 9(10) • The answer is 1879(10) Information Technology in Theory

  27. Binary Representation of Positive Nonintegers • But how can binary represent noninteger numbers? • Converting a noninteger number into binary is similar to converting an integer into binary • For example, consider the number 42.4375 • Finding the binary equivalent of this noninteger number requires the following steps: Information Technology in Theory

  28. Binary Representation of Positive Nonintegers (continued) • The integer part of 42.4375 is first converted into its binary equivalent using the procedures described previously • The binary equivalent of 42 is calculated to be 101010 • The fractional part of the decimal number (0.4375) is converted to binary by multiplying 0.4375 by 2 and comparing it to 1 Information Technology in Theory

  29. Binary Representation of Positive Nonintegers (continued) • If the result of the multiplication is greater than or equal to 1, then a bit with a value of 1 is noted, the fractional part of the multiplication result is extracted and multiplied by 2, and the result is compared to 1 • If the result of the multiplication is less than 1, then a bit with a value of 0 is noted and the number is multiplied by 2 again • Repeat until the result of the multiplication is 1 Information Technology in Theory

  30. Binary Representation of Positive Nonintegers (continued) Information Technology in Theory

  31. Converting the Binary Number 111.110 into Decimal Information Technology in Theory

  32. Representing Negative Integers in Binary • How can negative numbers be represented in binary? • Why not just add a preceding bit indicating the sign? • 5 might be represented as 0101 • -5 might be represented as 1101 • Limitations of binary addition preclude this approach Information Technology in Theory

  33. The Following Rules Apply to Binary Addition • 0 + 0 = 0 • 0 + 1 = 1 • 1 + 0 = 1 • 1 + 1 = 0 with a carry of 1 • 1 + 1 + carry of 1 = 1 with a carry of 1 • The addition of 0101 (+5) and 1101 (-5) based on the above rules results in: 0101 +1101 10010 Information Technology in Theory

  34. “2’s Complement Notation” Express -5 in 8-bit 2’s complement form • Step 1: Determine the 8-bit binary representation of 5 • 00000101 • Step 2: Take the “complement” of the binary pattern determined in Step 1 • Change all the 0s to 1s and change all the 1s to 0s • 11111010 • Step 3: Arithmetically add 1 to the binary pattern determined in Step 2 11111010 + 1 11111011 • The 8-bit 2’s complement of -5 is therefore 11111011 Information Technology in Theory

  35. “2’s Complement Notation” Express -7 in 16-bit 2’s complement form • Determine the 16-bit binary representation of 7 • 0000000000000111 • Take the “complement” of the binary pattern determined in Step 1 • 1111111111111000 • Add 1 to the binary pattern determined in Step 2 • 1111111111111001 Information Technology in Theory

  36. Alternative Numbering Systems • Long binary streams need to be made more manageable for humans • Shorthand notations • Octal (Base-8) • Hexadecimal (Base-16) Information Technology in Theory

  37. Octal • The octal numbering system, also called base 8, uses eight numbers • Counting in octal is identical to counting in decimal or binary, but octal uses eight numbers (0 through 7) instead of 10 or 2 • Because we run out of numbers at 7, the next number after 7 is 10 in octal • Counting in octal: • 0, 1, 2, 3, 4, 5, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 25, 26, 27, 30 Information Technology in Theory

  38. Convert the Octal Number 167 to Decimal • The seven is in the 80, or “1s place”; the six is in the 81, or “8s place”; and the one is in the 82, or “64s place” • The octal number 167 can be converted to decimal as follows: (1 × 64) + (6 × 8) + (7 × 1) = 64 + 48 + 7 = 119(10) • The octal number 167(8) = the decimal number 119(10) Information Technology in Theory

  39. Octal as a Shorthand for Binary Information Technology in Theory

  40. Binary to Octal Conversion • Convert the binary stream 111101000000 into octal • Break the number into groups of three starting from the right: 000, 000, 101, and 111 • Convert each group into its octal equivalent and place the resulting octal numbers in sequential order • 000 = 0 • 000 = 0 • 101 = 5 • 111 = 7 111101000000 = 7500(8) Information Technology in Theory

  41. Hexadecimal • Uses 16 characters • There are only 10 unique numbers, 0-9, so hexadecimal has to introduce alphabetic letters • Hexadecimal characters are: • 0, 1, 2, 3, 4, 5, 6, 7, 8 9, A, B, C, D, E, and F • The letter “A” symbolizes the tenth number, “B” symbolizes the eleventh number, and so forth Information Technology in Theory

  42. The Hexadecimal Numbering System 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2A, 2B, 2C, 2D, 2E, 2F, 30, 31, and so on Information Technology in Theory

  43. Hexadecimal as Shorthand Information Technology in Theory

  44. Hexadecimal as Shorthand (continued) Convert 1111101010110001(2) into hexadecimal shorthand: 0001 = 1 1011 = B 1010 = A 1111 = F 1111101010110001(2) = FAB1(16) Information Technology in Theory

  45. Comparison of Numbering Systems Information Technology in Theory

  46. Real-World Example of Hexadecimal as Shorthand Notation • 48-bit NIC address: 101000011111000001011011001010101100010000000001. • Break the address into groups of four and convert each group into its equivalent hexadecimal character: 1010 = A 0010 = 2 0001 = 1 1010 = A 1111 = F 1100 = C 0000 = 0 0100 = 4 0101 = 5 0000 = 0 1011 = B 0001 = 1 Information Technology in Theory

  47. Real-World Example of Hexadecimal as Shorthand Notation (continued) • The hexadecimal shorthand representation of the 48-bit address is A1F05B2AC401 Information Technology in Theory

  48. Representing Text and Other Characters in Binary • Binary code can represent text and alphanumeric characters • Two standards: • ASCII • Unicode Information Technology in Theory

  49. ASCII • Extended ASCII assigns an 8-bit code for each alphanumeric character • Recall that an 8-bit code can represent 28, or 256, unique items Information Technology in Theory

  50. Segment of ASCII Chart Information Technology in Theory

More Related