🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Chapter 6 - Computer Encoding System.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

FeasibleMaroon

Uploaded by FeasibleMaroon

Universiti Sains Malaysia

Tags

computer encoding ASCII binary numbers computer science

Full Transcript

CMPF134 Chapter 6 – Computer Encoding System 1 Chapter Objectives ◦ To be exposed to five common types of computer encoding system ◦ To be able to differentiate the characteristics of each computer encoding system ◦ To be a...

CMPF134 Chapter 6 – Computer Encoding System 1 Chapter Objectives ◦ To be exposed to five common types of computer encoding system ◦ To be able to differentiate the characteristics of each computer encoding system ◦ To be able to convert from BCD to Binary Number ◦ To be able to convert from Gray Code to Binary Number 2 Introduction ◦ Computer is a very useful digital device, whereby it assists human being in performing lots of complicated tasks (example: calculating monthly expenses, generating assignment report) ◦ Apart from numerical values, computing devices also handle textual data comprising characters. The character set includes letters in alphabets (a-z, A-Z), digits (0-9), special symbols (+ - ! %.....) and non-printable characters (example: backspace) ◦ As mentioned in earlier chapter, a computer can only understand two distinct types of data: on (1) and off (0) – binary numbers 3 Introduction (Cont.) ◦ A computer is a collection of on/off switches (transistor) located in the CPU. At a physical level, the 0s and 1s are stored in the central processing unit of a computer system using transistors ◦ Binary information is also transmitted using magnetic properties; the two different types of polarities are used to represent zeros and ones (so that data can be saved inside a magnetic storage media) ◦ No matter where the data is stored, all digital data (either numbers or characters) must be represented at the most fundamental level -- binary numbers, consists of zeros and ones 4 Introduction (Cont.) ◦ You have learnt how to convert numbers into their binary equivalent in chapter 1 and 2 ◦ The problem is, how do we represent texts (such as “Hello!!”) in binary forms so that it can be processed by the computer? ◦ The same logic used to represent numbers can be used to represent text 5 Introduction (Cont.) ◦ By the late 1950s, computers were getting more common, and they started to communicate with each others ◦ There was a pressing need for a standard way to represent textual data, so that it could be understood by different models and brands of computers during data transmission ◦ It can be accomplished with the existence of computer encoding system 6 Types of Computer Encoding System ◦Five common types of computer encoding system are: ASCII Unicode EBCDIC BCD Gray Code 7 ASCII ◦ Stands for American Standard Code for Information Interchange ◦ Published in 1960s by ANSI (American National Standard Institute) ◦ One of the earliest character coding scheme, developed from telegraphic codes ◦ Most widely used coding scheme for personal computers (except IBM Mainframe Computers) 8 ASCII (Cont.) ◦ It was originally designed as a 7-bit code  Can represent 27 = 128 characters  8th bit will act as the parity bit (also called a check bit) to make sure that data are transmitted correctly from sending device to receiving device ◦ It has then been extended to 8-bit code to better utilize the 8-bit computer memory organization  Can represent 28 = 256 characters  Extended 128 unique codes are used to represent graphic symbols  Requires a ninth bit for parity checking 9 ASCII (Cont.) ◦ ASCII characters can be split into the following sections by referring to their ASCII decimal value: 0 – 31: Control characters 32 – 127 : Standard alphanumeric characters we work with everyday 128 – 255 : Special symbols, non-standard characters (extended ASCII characters) 10 11 ASCII - Control Characters (Cont.) 12 13 ASCII – Standard Characters (Cont.) 14 ASCII – Standard Characters (Cont.) 15 16 ASCII – Extended Characters (Cont.) 17 Unicode ◦ Computers are largely invented in English-speaking countries (Britain and US). However, there is a whole world out there (Japan, Korea, China, India etc) and they are also digitalized now ◦ This raises a problem with current ASCII encoding system as it is not sufficient to represent alphabets of other languages ◦ Therefore, Unification Code (or Unicode) has been introduced in 1980s to unify all of the worlds’ character sets into a single large character set, known as Universal Character Set (UCS) 18 Unicode (Cont.) ◦ Developed and maintained by a non-profit organization, called the Unicode ® Consortium ◦ Started out by using 16-bit (2-Byte) code, therefore it is also called UCS - 2 (Universal Character Set – 2 Bytes) ◦ Allows more than 65, 000 distinct characters (216 combinations ) to be represented ◦ It is backward compatible with the 7-bit ASCII which makes the first 128 characters in Unicode to be the same as ASCII 19 Unicode (Cont.) ◦ Has three encoding forms: UTF-8, UTF-16 and UTF-32 ◦ It has been adopted by many industries, such as Apple, HP, IBM, Microsoft, Oracle… etc. ◦ It is capable to support many operating systems and web browser ◦ Besides that, it works on any computer language, platforms and programs 20 Unicode (Cont.) ◦ The Universal Character Set is coded in terms of integer values, which are referred to as Unicode Scalar Values (USVs) ◦ Unicode code points are represented in hexadecimal notation with a minimum four digits and preceded with “U+” ◦ Example: U+0061 LATIN SMALL LETTER A  U+0061  code point  0061  USV  LATIN SMALL LETTER A  name of character, written entirely in uppercase 21 Unicode (Cont.) ◦ In the original design of Unicode, all characters were to have code points in the range of U+0000 to U+FFFF 22 EBCDIC ◦ Stands for Extended Binary Coded Decimal Interchange Code ◦ First used on the IBM 360 computers, which was presented to the market in 1980s ◦ Generally found on IBM mainframe computers or in systems which interact with them ◦ Expanded from IBM 6-bit code, known as BCDIC (Binary Coded Decimal Interchange Code) ◦ Represents character by using 8-bit code, it is possible to form 256 different bits combinations (hence, can represent 256 different characters) 23 EBCDIC (Cont.) ◦ EBCDIC code is shown in “zone-digit” form ◦ The first nibble (four bits) is called the zone which represents the category of the character, while the last nibble is called the digit and it identifies the specific character. ◦ Example (refer to EBCDIC table 1): Zone bits 1100 is used for alphabetic characters A – I Zone bits 1101 is used for characters J – R Zone bits 1110 is used for character S – Z Zone bits 1111 is used to represent decimal digits 24 EBCDIC Table (1) 25 EBCDIC Table (1) (Cont.) 26 EBCDIC (Cont.) ◦ EBCDIC characters set consists of four main blocks (refer to EBCDIC table 2): 0000 0000 to 0011 1111 – control characters (wider range of control characters than ASCII) 0100 0000 to 0111 1111 – punctuation marks 1000 0000 to 1011 1111 – lowercase characters 1100 0000 to 1111 1111 – uppercase characters and numbers 27 EBCDIC Table (2) 28 EBCDIC (Cont.) ◦ Even though both EBCDIC and ASCII encoding system represent characters by using 8-bits code, same character will not share the same combination of 8-bit code for both EBCDIC and ASCII ◦ For example, let's look at the characters “DP3” in both EBCDIC and ASCII Character D P 3 Encoding system ASCII 0100 0100 0101 0000 0011 0011 EBCDIC 1100 0100 1101 0111 1111 0011 29 BCD ◦ In electronic systems, binary-coded decimal (BCD) is a method for representing decimal numbers in which each decimal digit is represented by 4 binary digits ◦ Advantages: This makes it relatively easy for the system to convert the numeric representation for printing or display purposes (especially in digital clocks, digital thermometers, and other electronic devices with seven- segment display) Speeds up decimal calculations 30 BCD (Cont.) ◦ Disadvantages: representing decimal numbers in this way takes up more space in memory than using a more conventional binary representation The circuitry required to carry out calculations also tends to be more complex 31 BCD (Cont.) Decimal Natural Binary Coded ◦ BCD code is also known as number Binary Decimal(BCD) 8421 code because each 0 0000 0000 1 0001 0001 decimal digit (0-9) is 2 0010 0010 represented with 4-bit code 3 0011 0011 (weighted 23, 22, 21, 20 4 0100 0100 5 0101 0101 respectively) 6 0110 0110 7 0111 0111 ◦ Note that values greater 8 1000 1000 than 1001 (1010, 1011, 1100, 9 1001 1001 1101, 1110, or 1111) 10 1010 0001 0000 11 1011 0001 0001 are not valid BCD decimal 12 1100 0001 0010 values 13 1101 0001 0011 14 1110 0001 0100 15 1111 0001 0101 32 BCD (Cont.) ◦ To express any decimal number in BCD, simply replace each decimal digit with the appropriate 4-bit code ◦ Example 1: Convert each of the following decimal numbers into BCD Decimal digit 5 1. 5 BCD 0101 Decimal digit 3 5 2. 35 BCD 0011 0101 Decimal digit 9 8 3. 98 BCD 1001 1000 Decimal digit 1 7 0 4. 170 BCD 0001 0111 0000 Decimal digit 2 4 6 9 5. 2469 BCD 0010 0100 0110 1001 33 BCD (Cont.) ◦ It is equally easy to determine a decimal number from a BCD number ◦ Start at the LSB and break the code into groups of 4-bit ◦ Then identify the appropriate decimal digit represented by each 4- bit group 34 BCD (Cont.) ◦ Example 2: Convert each of the following BCD codes to decimal number BCD 1000 0110 a. 10000110BCD Decimal Digit 8 6 BCD 0011 0101 0001 b. 001101010001BCD Decimal Digit 3 5 1 BCD 1001 0100 0111 0000 c. 1001010001110000BCD Decimal Digit 9 4 7 0 d. 001001100100BCD BCD 0010 0110 0100 Decimal Digit ?? ?? ?? e. 100110000011BCD BCD ?? ?? ?? Decimal Digit ?? ?? ?? 35 Gray Code ◦ Invented by Frank Gray, also known as Reflected Binary Code ◦ Is a type of unweighted binary code, which means there are no specific weights assigned to each bit position, therefore it is not applicable for arithmetic calculations ◦ The important feature of Gray Code is that it exhibits only a single bit change from one code word to the next in sequence ◦ This allows system designer to perform error checking as the data must be incorrect if more than one bit has been changed during each count (each transition from one number / position to the next adjacent one) 36 Gray Code Table A gray code can have ANY number of bits, not necessarily 4-bit code only 37 Gray Code (Cont.) ◦ Imagine in natural binary number system, as many as four digit could change for a single count ◦ For example: ◦ Transition from binary 0111 to 1000 (decimal number 7 to 8) involves the changes towards all the four binary digits ◦ But transition from gray code 0100 (710) to 1100 (810) involves only one bit of changes (at the MSB) ◦ Therefore, Gray Code is considered to be an error-minimizing code. ◦ Besides that, the speed of transition for Gray Code is faster than code changes for natural binary or BCD code 38 Application of Gray Code ◦ Gray codes are used with shaft position encoder for accurate control of robots and machine tools ◦ Three IR emitter/detectors are used to encode the position of the shaft ◦ Encoder on the left uses binary and can have three bits change together, creating a potential error. Encoder on the right uses gray code and only 1-bit changes, eliminating potential error. 39 Application of Gray Code (Cont.) ◦ Mathematical puzzle like “Tower of Hanoi” can be solved by using the concept of Gray Code as it allows only one plate to be shifted at a time 40 Gray Code vs Natural Binary ◦ Conversion from Gray Code to Binary number can be performed by applying the logic of Exclusive-OR gate 41 Conversion of Natural Binary to Gray Code Example 1: Binary 1 1 0 1 Convert 11012 into Gray Code Solution: 1. Retain MSB of binary number to be Gray 1 Gray Code’s MSB 2. 2nd bit of Gray code will be obtained Gray 1 0 by performing exclusive-or of the 1st bit and second bit of binary number Gray 1 0 1 3. Repeat until the last bit of binary number has been converted Gray 1 0 1 1 42 Conversion of Natural Binary to Gray Code (Cont.) Example 2: Binary 1 0 0 1 1 Convert 100112 into Gray Code Solution: Gray 1 1. Retain MSB of binary number to be Gray 1 1 Gray Code’s MSB 2. 2nd bit of Gray code will be obtained Gray 1 1 0 by performing exclusive-or of the 1st bit and second bit of binary number Gray 1 1 0 1 3. Repeat until the last bit of binary Gray 1 1 0 1 0 number has been converted 43 Conversion of Gray Code to Natural Binary Example 3: Gray 1 1 0 1 Convert Gray Code 11012 into its binary equivalent value Solution: Binary 1 1. Retain MSB of Gray code to be Natural Binary’s MSB Binary 1 0 2. 2nd bit of Natural Binary will be obtained by performing exclusive-or of Binary 1 0 0 the 1st bit of Natural Binary with 2nd bit of Gray Code Binary 1 0 0 1 3. Repeat until the last bit of Gray Code has been converted 44 Conversion of Gray Code to Natural Binary (Cont.) Example 4: Gray 1 0 0 1 1 Convert Gray Code 100112 into its binary equivalent value Solution: Binary 1 1. Retain MSB of Gray code to be Natural Binary 1 1 Binary’s MSB 2. 2nd bit of Natural Binary will be Binary 1 1 1 obtained by performing exclusive-or of the 1st bit of Natural Binary with 2nd bit Binary 1 1 1 0 of Gray Code Binary 1 1 1 0 1 3. Repeat until the last bit of Gray Code has been converted 45 Exercise 1 ◦ Convert each Gray Code below into it’s Natural Binary value a. 1012 b. 11002 c. 101012 d. 1001012 ◦ Convert each Binary Number below into Gray Code a. 1012 b. 11002 c. 101012 d. 1001012 46

Use Quizgecko on...
Browser
Browser