* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Topic: Manipulating Data
Survey
Document related concepts
Transcript
Lesson Plan 4 Information Technology Topic: Manipulating Data Objectives: Describe how data are stored and manipulated within the computer Binary, octal and hexadecimal number systems; Binary addition Sign and magnitude BCD (binary coded decimal) Two’s complement Representation of characters, ASCII A PowerPoint slide (Number Systems1.ppt) which would be given to students on their flash drives at the end of the week. Content: What is a Number System? A number system is the notational scheme used to represent quantities and is defined by the number of symbols needed to represent an infinite quantity of values. For Example: Decimal or Base 10 is a number system that uses 10 symbols – 0,1,2,3,4,5,6,7,8,9. Number Values In the initial stages, the symbol has only the value assigned In the first grouping, the symbol’s value is compounded by one group of the base Each additional grouping increases in value exponentially by the base Number Systems | 1 Standard Number Values 104 103 102 10,000 1,000 100 3 9 1 3 0 101 100 10 1 Number Values 8 5 (3x102)+(8x101)+(5x100) or 385 7 (7x100) or 7 8 2 8 8 0 0 0 1 5 0 1 0 9 9 1 2 6 8 5 4 Other Number Systems There are several number systems used throughout history. The Babylonians used the sexagesimal system, based on the number 60, The Romans used (for some purposes) the duodecimal system, based on the number 12. The Mayas used the vigesimal system, based on the number 20. Number Systems used today Binary Octal Decimal Hexadecimal – - Base 2 Base 8 Base 10 Base 16 The principles governing each of the number systems are the same. The only difference is the number of symbols used in the system. Number Systems | 2 Binary Octal Decimal Hexadecimal (Base 2) (Base 8) (Base 10) (Base 16) 0 0 0 0 1 1 1 1 10 2 2 2 11 3 3 3 100 4 4 4 101 5 5 5 110 6 6 6 111 7 7 7 1000 10 8 8 1001 11 9 9 1010 12 10 A 1011 13 11 B 1100 14 12 C 1101 15 13 D 1110 16 14 E 1111 17 15 F 10000 20 16 10 11111111 377 255 FF 1.11E+10 3721 2001 7D1 For example, additions: Binary Octal Hexadecimal Number Systems | 3 The class would be shown how to convert from decimal to binary and vice versa. Examples were shown and then the following exercises would be given: Class Activity Converting from decimal to binary: a) 63 b) 25 c) 54 d) 81 e) 12 Converting from binary to decimal: a) 10110111 b) 10101010 c) 10001111 Class Activity 1. Compute the following Binary additions. a) 1101 + 0111 b) 1011011 + 1000110 d) 10111111 + 00101110 e) 10111 + 10011 c) 1101101 + 1010101 f) 110111 + 101101 Home Work 2. Compute the following Octal additions. a) 1725 + 0576 b) 1016637 + 1564711 d) 13133777 + 00666666 e) 215401 + 565247 c) 7654123 + 2657321 f) 645355 + 236500 Class Activity 3. Compute the following Hexadecimal additions. a) 1F24 + 028A b) 0028F1F + BBAD02 d) 69879999 + A2897995 c) 124B0D + EE20C1 Negative Numbers There are several systems used to represent negative and positive integers: Sign and Magnitude One’s Complement Two’s Complement Binary Coded Decimal Number Systems | 4 Sign and Magnitude It uses one bit (usually the leftmost) to indicate the sign. "0" indicates a positive integer, and "1" indicates a negative integer. The rest of the bits are used for the magnitude of the number. For example, -2510 is represented as: 1001 1001 The sign "1" means negative The magnitude is 25 (in 7-bit binary) Examples: Convert the following sign and magnitude 8-bit: 1) -6310 2) -4210 3) -7010 4) 3010 5) 4310 Steps: Convert the number given to binary, ignoring the sign of the number If a specific number of bits is required, add zeros on the left of the binary value Change the leftmost bit of the answer to binary 1, if a minus sign is required or 0 for a plus sign. Question With 8-bit sign-magnitude representation, what positive integers can be represented and what negative integers can be represented? Answer: -12710 ... -0, 0 ... 12710 The leftmost bit is used for the sign, which leaves seven bits for the magnitude. The magnitude uses 7-bit unsigned binary, which can represent 010 (as 000 0000) up to 12710 (as 111 1111). The eighth bit makes these positive or negative, resulting in -12710 ... -0, 0 ... 12710. One’s Compliment In ones' complement, the inverse of a number is formed by complementing each bit. Convert the number to binary, ignoring the sign of the number Add any required zeros on the left of the binary value so that it would meet the bit requirement. Change all 0s to 1s and all 1s to 0s Number Systems | 5 Two’s Compliment This is a binary number that is created by reversing all the bits and then adding 1 if the number is negative. In computing, the two's complement often is used to represent negative numbers. For example, to find the 8-bit two's complement of "-1", which is "00000001", reverse each of the bits to get "11111110" and then add "1" to get "11111111". Convert the value from decimal to binary Present the answer using the instructed number of bits by adding zeros to the left If the number is positive, then this is the answer, if not, then follow the other steps Change all 0s to 1s and all 1s to 0s to invert the bits of the binary number Add one to the answer if the number using binary addition Class Activity Convert to 8-bit One’s Complement and Two Complement: 1) 2) 3) 4) 5) -3410 -2710 -1710 -4110 -5310 Binary Coded Decimal Binary-coded decimal, or BCD, is a method of using binary digits to represent the decimal digits 0 through 9. This involves converting each decimal digit to its four-digit equivalent. 0 1 2 3 4 0000 0001 0010 0011 0100 5 6 7 8 9 0101 0110 0111 1000 1001 Even the signs are assigned a four-bit code: + = 1110 – = 1111 Examples would be used to allow students to practice sign and magnitude, one’s complement, two’s complement and binary coded decimal. Home Work Convert the following to BCD: 1) -56710 2) -48910 4) -28210 5) -17310 3) -36110 Number Systems | 6 Representing Alphanumeric Characters Every piece of data that is input into a computer, whether it is a number, symbol or some other character, it would be represented inside the computer by binary codes (since this is the language the computer understands). Each symbol is represented by a different code. There are two coding systems that provide a unique binary character code for each character for use in the computer. They are: ASCII – American Standard Code for Information Interchange EBCDIC – Extended Binary Code Decimal Interchange Code ASCII This is a character encoding system used to define a set of characters which can be displayed by a computer on a screen, as well as some control characters which have special functions. This coding system is used on most microcomputers and represents the symbols as a 7 or 8 bit binary code. The codes are sequential for the alphabet and for numbers. For example, if A is represented as 1000001, then B would be 10000010. (To make it 8 bit add a 0 to the left). Converting in ASCII: If we know the ASCII code for ‘A’ is 1000001, we can find the code for ‘H’. To do this: 512 256 128 64 32 16 8 4 2 Convert the binary code to decimal. (1000001 = 64 + 1 = 65) Determine how far the required letter is from the letter given. (‘H’ is 7 letters after ‘A’) Add this number to the decimal value. (65 + 7 = 72) Convert this final decimal value to binary. 72 = 1001000 in binary Therefore the ASCII CODE FOR ‘H’ is 1001000. Character 0 1 2 3 4 5 ASCII Code 00110000 00110001 00110010 00110011 00110100 00110101 Character A B C D E F ASCII Code 01000001 01000010 01000011 01000100 01000101 01000110 Character N O P Q R S ASCII Code 01001110 01001111 01010000 01010001 01010010 01010011 Number Systems | 7 1 6 7 8 9 00110110 00110111 00111000 00111001 G H I J K L M 01000111 01001000 01001001 01001010 01001011 01001100 01001101 T U V W X Y Z 01010100 01010101 01010110 01010111 01011000 01011001 01011010 Abbreviation of Extended Binary-Coded Decimal Interchange Code. Pronounced eb-sih-dik, EBCDIC is an IBM code for representing characters as numbers. Although it is widely used on large IBM computers, most other computers, including PCs and Macintoshes, use ASCII codes. EBCDIC, Extended Binary Coded Decimal Interchange Code, was developed in 1963 by IBM as an extension to the older Binary Coded Decimal (BCD) standard. BCD encodes the 10 digits of the standard counting system using 4 binary counters, or bits, where an individual bit can be either a 1 or a 0. BCD for Numeric Characters Digit EBCDIC 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 EBCDIC is eight bits, or one byte, wide. Each byte consists of two nibbles, each four bits wide. The first four bits define the class of character, while the second nibble defines the specific character inside that class. For example, setting the first nibble to all-ones, 1111, defines the character as a number, and the second nibble defines which number is encoded. In recent years, EBCDIC has been expanded to 16- and 32-bit variants to allow for representation of large, non-latin character sets. Each EBCDIC variant is known as a codepage, identified by its Coded Character Set Identifier, or CCSID. EBCDIC codepages have been created for a number of major writing scripts, including such complex ones as Chinese, Korean and Japanese. Number Systems | 8 All IBM mainframe computers, even the most recent models, continue to support EBCDIC so that legacy applications can be run without modification. References: 1) 2) 3) 4) 5) 6) 7) Oxford Information Technology for CXC CSEC by Glenda Gay and Ronald Blades Introduction to Information Systems by James A. O’Brien http://chortle.ccsu.edu/AssemblyTutorial/Chapter-08/ass08_13.html http://www.tpub.com/neets/book13/53s.htm http://www.computerhope.com/jargon/t/twocompl.htm www.wikipedia.com http://www.wisegeek.com Number Systems | 9