1 / 41

Coding

Coding. Lesson 2 0x002 010. Number Systems. Coding Decimal number system Binary number system Octal number system Hexadecimal number system Conversion. Coding. Computer. Keyboard. Screen. Decoding. Scanner. Coding. Printer. Mouse. Microphone.

lucas
Télécharger la présentation

Coding

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. Coding Lesson 2 0x002010

  2. Number Systems • Coding • Decimal number system • Binary number system • Octal number system • Hexadecimal number system • Conversion

  3. Coding Computer Keyboard Screen Decoding Scanner Coding Printer Mouse Microphone All Information are converted into codes to be processed by the computer. The codes are numbers in the Binary System (1s & 0s) Why Binary ?

  4. Decimal Number System • This is the used number system in our life calculations. • It contains 10 symbols to represent the numbers which are {0,1,2,3,4,5,6,7,8,9}, any number in the system can be represented in away that it depends on the power of 10.

  5. Decimal (base 10) Examples: 2434=2000+400+30+4 =2x1000 + 4x100 + 3x10 + 4x1 =2x103 + 4x102 +3x101 + 4x100 Example 2: 1479 = 1 * 103 + 4 * 102 + 7 * 101 + 9 * 100

  6. Binary Number system • This number system contains only two symbols to represent its numbers, which are {0 and 1} only. • e.g.: 100, 101 1000001010 are accepted numbers in the binary system where 10020 is not accepted because it contains the symbol (2) which is not included in the set of symbols. • In order to distinguish the numbers in the binary system from the decimal system, they are put in parenthesis and the number 2 is put to the bottom right of the brackets as a subscript; like (1001)2 for the binary system , and the number 10 is put to for the decimal system ; like (1001)10.

  7. Conversion from Binary to Decimal 1 1 0 1 Example: (1101) 2 = 8x1 + 4x1 + 2x0 +1x1 = (13) 10 0 0 1 • (100)2= 1x22 + 0x21 + 0x 20 • =1x4 + 0x2 + 0x1 • =4 + 0 +0= (4)10

  8. Conversion from Binary to Decimal • Exercise: What are the decimal values for the following binary numbers: a- (10010)2 b- (1110111)2 c- (1011011)2 1 0 1 1 (1011)2=1x23 + 0x22 + 1x 21 + 1x 20 =1x 8 + 0x4 + 1 x 2 + 1 x 1 = 8 + 0 +2 +1=(11)10

  9. Conversion from Binary to Decimal Rule: If the binary number consists of only ones, you can find its decimal equivalent number using this formula: Decimal = 2n – 1 Where n is the number of bits, for example 1111 has 4 bits. Example 1: (11111111)2 has 8 bits, so Decimal = 28 – 1 = 255 Example 2: (111111111)2 has 9 bits, so Decimal = 29 – 1 = 511

  10. Conversion from Binary to Decimalfraction Examples Convert binary to decimal: 1) 2) (110.001)2 (101110.101)2 Sol. Sol. 1 1 0 . 0 0 1 1 0 1 1 1 0 . 1 0 1 4 2 1 . .5 .25 .125 32 16 8 4 2 1 . .5 .25 .125 4 2 1 . .5 .25 .125 32 16 8 4 2 1 . .5 .25 .125 = 4 +2 + .125 = (6.125)10 =32 + 8 + 4 +2 + .5 + .125 =(46.625)10

  11. Decimal to binary conversion Example: 43 43 ÷ 2: Quotient 21, remainder 1: Result > 1 21 ÷ 2: Quotient 10, remainder 1: Result > 1 1 10 ÷ 2: Quotient 5, remainder 0: Result > 0 1 1 5 ÷ 2: Quotient 2, remainder 1: Result > 1 0 1 1 2 ÷ 2: Quotient 1, remainder 0: Result > 0 1 0 1 1 1 ÷ 2: Quotient 0, remainder 1: Result > 1 0 1 0 1 1 • Exercise: Convert the following decimal numbers to binary • 22 • 63 • 174 • 3000

  12. Decimal to binary conversion

  13. Fractions conversion from decimal to binary

  14. Fractions conversion from decimal to binary

  15. Count…

  16. Count… Exercise: convert the following decimal numbers to binary: a- (85) b- (117) c- (43.75) d- (0.15625) e- (36.045) 2- Arrange the following binary numbers in ascending order a- 1101 b- 1110 c- 1011.11 d- 1101.001

  17. Octal Number system This system contains 8 digits (symbols) which are the first 8 decimal digits (0,1,2,3,4,5,6,7); (there are no 8 & 9 in the octal number system). Valid numbers in octal system: 45612 70125 20 10001 Invalid numbers in octal system: 455801 94 8000 Numbers are presented in this systems in parentheses with subscript 8 to separate them among other number system e.g. (45612)8

  18. Octal Number (base 8) • Example: convert (3057)8 to decimal. • Sol. 3057=3x83+0x82+5x81+7x80 • =3x512+0x64+5x8+7x1 • =1536+0+40+7 • =1583 • then (3057)8 is equivalent to (1583)10

  19. Decimal to octal conversion • Example 1: (173)10 • Sol. Remainder • 173 8 5 • 21 8 5 • 2 8 2 • The result is ( 25 5)8

  20. Example 2: (1583)10Sol. Remainder 1583 8 197 8 7 24 8 5 3 8 0 0 3The result is ( 3057)8 Example 2: (1583)10 Sol. Remainder 1583 8 1978 7 248 5 38 0 0 3 The result is ( 3057)8

  21. Converting decimal fractions to octal This can be obtained by multiply the decimal fraction by 8 and watch the carry into integer’s position. Example: (0.23)10 0.23 x 8 =1.84 1 0.84 x 8 = 6.72 6 0.72 x 8 = 5.76 5 ∴ (0.23)10 ≡ (0.165)8

  22. Octal to binary conversion Because 8 = 23 , we can convert from octal to binary directly, that is each digit in octal will match 3 digits in binary as follows:

  23. CONT…

  24. Binary to octal conversion • Binary to octal conversion: this conversion can be obtained as an opposite to the conversion from octal to binary that is grouping the binary number into threes, and converting them to octal ones. • Examples: convert from binary to octal. • Answer: 111001101 111 001 101 • 7 1 5 • ∴(111 001 101)2≡ (715)8

  25. Hexadecimal Number system This system contains sixteen symbols to represent its numbers, Which are: {0,1, 2, 3 ,4,5,6,7,8,9,A,B,C,D,E,F} Where A represent the value (10)10, B represent (11)10, C represent (12)10, D represent (13)10, E represent (14)10, F represent (15)10.

  26. Cont…. Valid numbers in hexadecimal numbers: 78A 100 A4BB To distinguish hexadecimal number from other systems, we put the hexadecimal numbers between two parenthesis like (49B3)16. The weights of the numbers in hexadecimal number system are evaluated according to the positional number system:

  27. Converting from hexadecimal to decimal: Examples: (34)16 Solution: 3x161 + 4x160 =3x16 + 4x1 =48+4 =(52)10(34)16  (52)10 (40AC)16 Solution: 4 x 163 + 0 x 162 + Ax161 + Cx160 =4 x 4096 + 0 x 265 + 10 x 16 + 12 x 1 =16384 + 0 + 160 + 12 =(16556)10 (40AC)16  (16556)10

  28. Converting from decimal to hexadecimal:

  29. Converting from hexadecimal to Binary: • because 16=24 then a hexadecimal number can be converted directly to 4 binary digits ass follows:

  30. Converting from hexadecimal to Binary:

  31. Converting from Binary to hexadecimal: • we group each 4 numbers to convert them into one hexadecimal number.

  32. Conversion Diagram Octal(8) by the Base and take the reminder Use the table directly Decimal(10) Binary(2) By the Weight and take the Sum Hex(16)

  33. ASCII Code • ASCII stands for American Standard Code for Information Interchange. • The ASCII is a 7 bits code whose format is X6X5X4X3X2X1X0, where each X is 0 or 1. • The ASCII code is used to represent the English language characters (letters, numbers, symbols and punctuations) by binary numbers to used in computers.

  34. Cont.... ASCII Code • Notes: • In computer processing the “space” is a significant character, where the ASCII code of the space is 0100000 . • Upper case and lower case letters have different values in ASCII code. • For example the ASCII code for A is 1000001 and the ASCII code for a is 1100001.

  35. Ascii Code

  36. Example: Write Print S in ASCII code. P(101 0000) r(111 0010) i(110 1001) n(110 1110) t(111 0100) space(010 0000) S(101 0011)

  37. Parity Bit • Note: Read page number 122 from the book. • The parity bit is an additional bit added to the ASCII code to catch errors in transmitting data. • So, the message format for each character (ASCII code with parity bit) is X7X6X5X4X3X2X1X0 ASCII Parity ِbit

  38. Types of Parity Bit: • Odd Parity Bit: in this type number of ones in the message for each character (ASCII code and parity bit) must be odd. • Even Parity Bit: in this type number of ones in the message for each character (ASCII code and parity bit) must be even.

  39. Suppose that twodevices are communicating witheven parity. • The transmitting device (Sender) sends data, it counts the number of ones in each groupof seven bits. If number of ones is even, it sets the parity bit to 0; if the number of ones is odd, it sets the parity bit to 1. • In this way, every message has an even number of ones.

  40. Cont... Parity Bit • On the receiving side, the device checks each message to make sure that it has an even number of ones. • If the receiving device finds an odd number of ones, the receiver knows there was an error during transmission.

  41. Binary Coded Decimal(BCD): • a format for representing decimal numbers (integers) in which each digit is represented by four bits . For example, the number 375 would be represented as:

More Related