This document discusses computer codes and their use in representing data internally in computers. It covers common computer codes like BCD, EBCDIC, and ASCII. BCD uses 6 bits to represent symbols and can encode 64 characters. EBCDIC and ASCII both use 8 bits, allowing 256 possible encodings. The document provides examples of how letters, numbers and other symbols are represented in the binary codes. It also discusses numeric representation using zoned decimal and packed decimal formats.
This document discusses computer codes and their use in representing data internally in computers. It covers common computer codes like BCD, EBCDIC, and ASCII. BCD uses 6 bits to represent symbols and can encode 64 characters. EBCDIC and ASCII both use 8 bits, allowing 256 possible encodings. The document provides examples of how letters, numbers and other symbols are represented in the binary codes. It also discusses numeric representation using zoned decimal and packed decimal formats.
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K.
Sinha & Priti Sinha
Slide 1/30 Chapter 4: Computer Codes Ref. Page Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 2/30 Chapter 4: Computer Codes Ref. Page In this chapter you will learn about: Computer data Computer codes: representation of data in binary Most commonly used computer codes Collating sequence Learning Objectives Learning Objectives 36 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 3/30 Chapter 4: Computer Codes Ref. Page Numeric Data consists of only numbers 0, 1, 2, , 9 Alphabetic Data consists of only the letters A, B, C, , Z, in both uppercase and lowercase, and blank character Alphanumeric Data is a string of symbols where a symbol may be one of the letters A, B, C, , Z, in either uppercase or lowercase, or one of the digits 0, 1, 2, , 9, or a special character, such as + - * / , . ( ) = etc. Data Types Data Types 36 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 4/30 Chapter 4: Computer Codes Ref. Page Computer codes are used for internal representation of data in computers As computers use binary numbers for internal data representation, computer codes use binary coding schemes In binary coding, every symbol that appears in the data is represented by a group of bits The group of bits used to represent a symbol is called a byte Computer Codes Computer Codes (Continued on next slide) 36 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 5/30 Chapter 4: Computer Codes Ref. Page As most modern coding schemes use 8 bits to represent a symbol, the term byte is often used to mean a group of 8 bits Commonly used computer codes are BCD, EBCDIC, and ASCII Computer Codes Computer Codes (Continued from previous slide..) 36 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 6/30 Chapter 4: Computer Codes Ref. Page BCD stands for Binary Coded Decimal It is one of the early computer codes It uses 6 bits to represent a symbol It can represent 64 (2 6 ) different characters BCD BCD 36 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 7/30 Chapter 4: Computer Codes Ref. Page 43 0011 10 L 44 0100 10 M 41 0001 10 J 42 0010 10 K 71 1001 11 I Octal BCD Code Char Digit Zone 70 1000 11 H 67 0111 11 G 66 0110 11 F 65 0101 11 E 64 0100 11 D 63 0011 11 C 62 0010 11 B 61 0001 11 A 22 0010 01 S 23 0011 01 T 24 0100 01 U 25 0101 01 V 26 0110 01 W 27 0111 01 X 30 1000 01 Y 31 1001 01 Z 51 1001 10 R Octal BCD Code Char Digit Zone 50 1000 10 Q 47 0111 10 P 46 0110 10 O 45 0101 10 N Coding of Alphabetic and Numeric Characters in BCD Coding of Alphabetic and Numeric Characters in BCD (Continued on next slide) 37 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 8/30 Chapter 4: Computer Codes Ref. Page Octal Equivalent BCD Code Character Digit Zone 12 1010 00 0 11 1001 00 9 10 1000 00 8 07 0111 00 7 06 0110 00 6 05 0101 00 5 04 0100 00 4 03 0011 00 3 02 0010 00 2 01 0001 00 1 Coding of Alphabetic and Numeric Characters in BCD Coding of Alphabetic and Numeric Characters in BCD (Continued from previous slide..) 37 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 9/30 Chapter 4: Computer Codes Ref. Page Example Show the binary digits used to record the word BASE in BCD Solution: B = 110010 in BCD binary notation A = 110001 in BCD binary notation S = 010010 in BCD binary notation E = 110101 in BCD binary notation So the binary digits 110010 110001 010010 110101 B A S E will record the word BASE in BCD BCD Coding Scheme (Example 1) BCD Coding Scheme (Example 1) 38 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 10/30 Chapter 4: Computer Codes Ref. Page Example Using octal notation, show BCD coding for the word DIGIT Solution: D = 64 in BCD octal notation I = 71 in BCD octal notation G = 67 in BCD octal notation I = 71 in BCD octal notation T = 23 in BCD octal notation Hence, BCD coding for the word DIGIT in octal notation will be 64 71 67 71 23 D I G I T BCD Coding Scheme (Example 2) BCD Coding Scheme (Example 2) 38 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 11/30 Chapter 4: Computer Codes Ref. Page EBCDIC stands for Extended Binary Coded Decimal Interchange Code It uses 8 bits to represent a symbol It can represent 256 (2 8 ) different characters EBCDIC EBCDIC 38 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 12/30 Chapter 4: Computer Codes Ref. Page D1 0001 1101 J D2 0010 1101 K D3 0011 1101 L D4 0100 1101 M C9 1001 1100 I Hex EBCDIC Code Char Zone Digit C8 1000 1100 H C7 0111 1100 G C6 0110 1100 F C5 0101 1100 E C4 0100 1100 D C3 0011 1100 C C2 0010 1100 B C1 0001 1100 A E2 0010 1110 S E3 0011 1110 T E4 0100 1110 U E5 0101 1110 V E6 0110 1110 W E7 0111 1110 X E8 1000 1110 Y E9 1001 1110 Z D9 1001 1101 R Hex EBCDIC Code Char Zone Digit D8 1000 1101 Q D7 0111 1101 P D6 0110 1101 O D5 0101 1101 N Coding of Alphabetic and Numeric Characters in EBCDIC Coding of Alphabetic and Numeric Characters in EBCDIC (Continued on next slide) 39 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 13/30 Chapter 4: Computer Codes Ref. Page Hexadecima l Equivalent EBCDIC Code Character Zone Digit F9 1001 1111 9 F8 1000 1111 8 F7 0111 1111 7 F6 0110 1111 6 F5 0101 1111 5 F4 0100 1111 4 F3 0011 1111 3 F2 0010 1111 2 F1 0001 1111 1 F0 0000 1111 0 Coding of Alphabetic and Numeric Characters in EBCDIC Coding of Alphabetic and Numeric Characters in EBCDIC (Continued from previous slide..) 39 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 14/30 Chapter 4: Computer Codes Ref. Page Zoned decimal numbers are used to represent numeric values (positive, negative, or unsigned) in EBCDIC A sign indicator (C for plus, D for minus, and F for unsigned) is used in the zone position of the rightmost digit Zones for all other digits remain as F, the zone value for numeric characters in EBCDIC In zoned format, there is only one digit per byte Zoned Decimal Numbers Zoned Decimal Numbers 39 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 15/30 Chapter 4: Computer Codes Ref. Page D for negative F3F4D5 -345 C for positive F3F4C5 +345 F for unsigned F3F4F5 345 Sign Indicator EBCDIC Numeric Value Examples Zoned Decimal Numbers Examples Zoned Decimal Numbers 40 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 16/30 Chapter 4: Computer Codes Ref. Page Packed decimal numbers are formed from zoned decimal numbers in the following manner: Step 1: The zone half and the digit half of the rightmost byte are reversed Step 2: All remaining zones are dropped out Packed decimal format requires fewer number of bytes than zoned decimal format for representing a number Numbers represented in packed decimal format can be used for arithmetic operations Packed Decimal Numbers Packed Decimal Numbers 39 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 17/30 Chapter 4: Computer Codes Ref. Page 03456F F3F4F5F6 3456 345D F3F4D5 -345 345C F3F4C5 +345 345F F3F4F5 345 Sign Indicator EBCDIC Numeric Value Examples of Conversion of Zoned Decimal Numbers to Packed Decimal Format Examples of Conversion of Zoned Decimal Numbers to Packed Decimal Format 40 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 18/30 Chapter 4: Computer Codes Ref. Page Example Using binary notation, write EBCDIC coding for the word BIT. How many bytes are required for this representation? Solution: B = 1100 0010 in EBCDIC binary notation I = 1100 1001 in EBCDIC binary notation T = 1110 0011 in EBCDIC binary notation Hence, EBCDIC coding for the word BIT in binary notation will be 11000010 11001001 11100011 B I T 3 bytes will be required for this representation because each letter requires 1 byte (or 8 bits) EBCDIC Coding Scheme EBCDIC Coding Scheme 40 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 19/30 Chapter 4: Computer Codes Ref. Page ASCII stands for American Standard Code for Information Interchange. ASCII is of two types ASCII-7 and ASCII-8 ASCII-7 uses 7 bits to represent a symbol and can represent 128 (2 7 ) different characters ASCII-8 uses 8 bits to represent a symbol and can represent 256 (2 8 ) different characters First 128 characters in ASCII-7 and ASCII-8 are same ASCII ASCII 40 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 20/30 Chapter 4: Computer Codes Ref. Page 38 1000 0011 8 Hexadecimal Equivalent ASCII-7 / ASCII-8 Character Digit Zone 39 1001 0011 9 37 0111 0011 7 36 0110 0011 6 35 0101 0011 5 34 0100 0011 4 33 0011 0011 3 32 0010 0011 2 31 0001 0011 1 30 0000 0011 0 Coding of Numeric and Alphabetic Characters in ASCII Coding of Numeric and Alphabetic Characters in ASCII (Continued on next slide) 42 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 21/30 Chapter 4: Computer Codes Ref. Page 4D 1101 0100 M 4C 1100 0100 L 4B 1011 0100 K 49 1001 0100 I Hexadecimal Equivalent ASCII-7 / ASCII-8 Character Digit Zone 4A 1010 0100 J 48 1000 0100 H 47 0111 0100 G 46 0110 0100 F 45 0101 0100 E 44 0100 0100 D 43 0011 0100 C 42 0010 0100 B 41 0001 0100 A Coding of Numeric and Alphabetic Characters in ASCII Coding of Numeric and Alphabetic Characters in ASCII (Continued from previous slide..) (Continued on next slide) 42 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 22/30 Chapter 4: Computer Codes Ref. Page 4E 1110 0100 N 4F 1111 0100 O 5A 1010 0101 Z 58 1000 0101 X Hexadecimal Equivalent ASCII-7 / ASCII-8 Character Digit Zone 59 1001 0101 Y 57 0111 0101 W 56 0110 0101 V 55 0101 0101 U 54 0100 0101 T 53 0011 0101 S 52 0010 0101 R 51 0001 0101 Q 50 0000 0101 P Coding of Numeric and Alphabetic Characters in ASCII Coding of Numeric and Alphabetic Characters in ASCII (Continued from previous slide..) 42 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 23/30 Chapter 4: Computer Codes Ref. Page Example Write binary coding for the word BOY in ASCII-7. How many bytes are required for this representation? Solution: B = 1000010 in ASCII-7 binary notation O = 1001111 in ASCII-7 binary notation Y = 1011001 in ASCII-7 binary notation Hence, binary coding for the word BOY in ASCII-7 will be 1000010 1001111 1011001 B O Y Since each character in ASCII-7 requires one byte for its representation and there are 3 characters in the word BOY, 3 bytes will be required for this representation ASCII-7 Coding Scheme ASCII-7 Coding Scheme 43 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 24/30 Chapter 4: Computer Codes Ref. Page Example Write binary coding for the word SKY in ASCII-8. How many bytes are required for this representation? Solution: S = 01010011 in ASCII-8 binary notation K = 01001011 in ASCII-8 binary notation Y = 01011001 in ASCII-8 binary notation Hence, binary coding for the word SKY in ASCII-8 will be 01010011 01001011 01011001 S K Y Since each character in ASCII-8 requires one byte for its representation and there are 3 characters in the word SKY, 3 bytes will be required for this representation ASCII-8 Coding Scheme ASCII-8 Coding Scheme 43 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 25/30 Chapter 4: Computer Codes Ref. Page Why Unicode: No single encoding system supports all languages Different encoding systems conflict Unicode features: Provides a consistent way of encoding multilingual plain text Defines codes for characters used in all major languages of the world Defines codes for special characters, mathematical symbols, technical symbols, and diacritics Unicode Unicode 44 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 26/30 Chapter 4: Computer Codes Ref. Page Unicode features (continued): Capacity to encode as many as a million characters Assigns each character a unique numeric value and name Reserves a part of the code space for private use Affords simplicity and consistency of ASCII, even corresponding characters have same code Specifies an algorithm for the presentation of text with bi-directional behavior Encoding Forms UTF-8, UTF-16, UTF-32 Unicode Unicode 44 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 27/30 Chapter 4: Computer Codes Ref. Page Collating sequence defines the assigned ordering among the characters used by a computer Collating sequence may vary, depending on the type of computer code used by a particular computer In most computers, collating sequences follow the following rules: 1. Letters are considered in alphabetic order (A < B < C < Z) 2. Digits are considered in numeric order (0 < 1 < 2 < 9) Collating Sequence Collating Sequence 46 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 28/30 Chapter 4: Computer Codes Ref. Page Example Suppose a computer uses EBCDIC as its internal representation of characters. In which order will this computer sort the strings 23, A1, 1A? Solution: In EBCDIC, numeric characters are treated to be greater than alphabetic characters. Hence, in the said computer, numeric characters will be placed after alphabetic characters and the given string will be treated as: A1 < 1A < 23 Therefore, the sorted sequence will be: A1, 1A, 23. Sorting in EBCDIC Sorting in EBCDIC 46 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 29/30 Chapter 4: Computer Codes Ref. Page Example Suppose a computer uses ASCII for its internal representation of characters. In which order will this computer sort the strings 23, A1, 1A, a2, 2a, aA, and Aa? Solution: In ASCII, numeric characters are treated to be less than alphabetic characters. Hence, in the said computer, numeric characters will be placed before alphabetic characters and the given string will be treated as: 1A < 23 < 2a < A1 < Aa < a2 < aA Therefore, the sorted sequence will be: 1A, 23, 2a, A1, Aa, a2, and aA Sorting in ASCII Sorting in ASCII 47 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Slide 30/30 Chapter 4: Computer Codes Ref. Page Alphabetic data Alphanumeric data American Standard Code for Information Interchange (ASCII) Binary Coded Decimal (BCD) code Byte Collating sequence Computer codes Control characters Extended Binary-Coded Decimal Interchange Code (EBCDIC) Hexadecimal equivalent Numeric data Octal equivalent Packed decimal numbers Unicode Zoned decimal numbers Key Words/Phrases Key Words/Phrases 47