Chapter 1 Representing Data in a Computer 数据在计算机中的表示 Main contents Common ways that representing data (数据)in microcomputer . number 数 character 字符
Aims Introduce common ways that representing data in computer Binary numbers(二进制数) Hexadecimal Numbers(十六进制数) ASCII codes for characters (ASCII 代码) BCD codes Calculation of Binary (二进制计算) Change between Binary and Hexadecimal(二进制和十六进制之间的转换)
Outcomes 1. Can convert among binary, decimal, and hexadecimal numbers. 2. Can differentiate(区分) and represent numeric and alphabetic information as integers, BCD, and ASCII data.
1.1 Binary and Hexadecimal Numbers Binary numbering System Hexadecimal numbering System Octal numbering System(八进制) Conversion of Integer between Binary , Hexadecimal and Decimal
Decimal Number(十进制) Being used in our life Base 10 Example: 36864=3×104+6 × 103+8 × 102+6 × 101+4 × 100
Binary Number Being used in computer Represent data in bits Binary digits , zero(0)/one(1) Base 2 Example: 1101b=1*23+1*22+0*21+1*20
Conversion between Binary Number and Decimal Number Convert from Decimal To Binary Divide DecimalNumber by 2(base of Binary),getting Quotient(商) and Remainder(余数) Remainder is the next digit(right to left); Example:5876 Convert from Binary to Decimal Multiply each bit by powers of 2 Example:1101110101b
Hexadecimal Number Binary Number is difficult to be read and write Hexadecimal Number is a convenient representation of binary numbers Base 16 0~9 ,A,B,C,D,E,F Example:3B8E2H
Conversion between Hexadecimal Number and Decimal Number Convert from Decimal To Hexadecimal Example:5876 Divide DecimalNumber by 16(base of hexadecimal), getting Quotient and Remainder Remainder is the next digit(right to left); Convert from hexadecimal to Decimal Example:8EFh Multiply each bit by powers of 16
Conversion between Hexadecimal Number and Binary Number Convert from Hexadecimal To Binary Substitute four bits for each hex digit Pading with leading zeros as needed E.g. 8EFh Convert from Binary to Hexadecimal From the right, breaking the binary number into groups of four bits Substitute the corresponding hex digit for each group of four bits E.g. 100b
Octal Number(八进制) Base 8 0~7 Example:123O
Conversion between binary and Octal Convert from Octal To Binary Substitute three bits for each octal digit Pading with leading zeros as needed E.g. 123o Convert from Binary to Octal From the right, breaking the binary number into groups of three bits Substitute the corresponding octal digit for each group of three bits E.g. 1011011b
1.2 Character Codes Character---Letters, numeral, punctuation marks and so on Assigning a numeric value to each character American Standard Code for Information Interchange(ASCII) is commonly used
ASCII Seven bits to represent characters, so 128 different characters can be represented using ASCII codes. Printable characters: 20h~7eh A~Z 41h~5ah a~z 61h~7ah 0~9 30h~39h Control characters:00h~1fh ESC 1bh , 0dh carriage return(CR,回车), 0AH line feed(LF,换行)
Computer Data Formats: BCD BCD digit 0000 ~ 1001 binary ( 00002 ~ 10012) 0 ~ 9 decimal Two forms Packed BCD (压缩): two digits per byte Unpacked BCD (非压缩): one digit per byte Decimal packed BCD unpacked BCD Hex 12 0001 0010 0000 0001 0000 0010 0CH 96 1001 0110 0000 1001 0000 0110 60H 96H 0906H
1.3 2‘s Complement Representation for Signed Integers To form a two’s complement Method one: Invert each bit of a number from 0 to 1 or from 1 to 0, then add a 1 Method two: Subtract the number by 0 +8 = 00001000 11110111 + 1 -8 = 11111000 0 =100000000 -(8= 00001000) -8 = 11111000
Byte-Sized Data One byte, 8 bits, 00H~FFH Unsigned integer (无符号整数): 0 ~ 255 signed integer (有符号整数): -128 ~ 0 ~ +127 Negative signed numbers are stored in the two’s complement form (补码) To store 8-bit data, use DB directive
Word-Sized Data Two bytes, 16 bits, 0000H~FFFFH Unsigned integer : 0 ~ 65,535 ( 216-1) signed integer : -32,768 ~ 0 ~ +32767 13400 = 3458H, 0 - 3458H = CBA8H So, -13400 = CBA8H in two’s complement Please note -1 = FFFFH (word-sized ) in two’s complement -1 = FFH (byte-sized ) in two’s complement
Data type (数据类型) Byte: 8bits Word:16bits Doubleword:32bits Quaword:64bits
1.4 Addition and subtraction of 2’s complement numbers Discusses addition(加法) and subtraction(减法) of 2’s complement numbers Introduces the concepts of carry (进位)and overflow(溢出)
Addition of hex numbers 2567 + 467 3034 0 A 0 7 + 0 1 D 3 0 B D A 7+3=10=A 0+D=0+13=13=D A+1=10+1=11=B 0+0=B BDAh=3034d
Addition of hex numbers signed number: 518+(-80)=438 unsigned number: 518+65456=65974 0206 + FFB0 101B6 0+6=6 carry 0+B=0+12=12=B 2+F=2+15=17=1+16(carry) 0+F+1(carry)=16=1+16(carry) 101B6h=65974(can’t be represented in a word) 01B6h=438
Addition of hex numbers signed number: (-25)+(-10)=-35 unsigned number: 65511+65526=131037 FFE7 + FFF6 1FFDD 7+6=13=D carry E+F=14+15=29=16 (carry) +13=D F+F=15+15+1 (carry) =31=15+16(carry)=F F+F+1(carry)=31=15+16(carry)=F 1FFDDh=131037(can’t be represented in a word) FFDDh=-35
Addition of hex numbers AC99 18495+25690=44185 OVERFLOW signed number: AC99H=-21351 unsigned number: AC99h=44185
Addition of hex numbers E9FF + 8CF0 176EF carry signed number: (-5633)+(-29456)=-35089 unsigned number: 59903+36080=95983 76EFH=30447 OVERFLOW
CARRY AND OVERFLOW Carry into sign bit? Carry out of sign bit? no yes
Examples: 0A07+01D3=? 0206+FFB0=? FFE7+FFF6=? 483F+645A=? E9FF+8CF0=?
Subtraction of hex numbers In a computer, subtraction a-b of numbers a and b is usually performed by taking the 2’s complement of b and adding the result to a. That means adding the negation of b.
BORROW 0 0 C 3 - 0 2 6 A 0 0 C 3 + F D 9 6 F E 5 9 195-618=-423 FE59H=-423 If there is no carry in the addition, then there is a borrow in the subtraction.
NO BORROW 0 3 D 9 - 0 1 9 B 0 3 D 9 + F E 6 5 1 0 2 3 E 985-411=574 023EH=574 If there is a carry in the addition, then there is no borrow in the subtraction.
-29123-15447=- 44570 (outside the range) OVERFLOW 8 E 3 D - 3 C 5 7 8 E 3 D + C 3 A 9 1 5 1 E 6 -29123-15447=- 44570 (outside the range) If overflow occurs in the addition, then it occurs in the original subtraction problem;if it does not occur in the addition, then it does not occur in the original subtraction.
QUESTION Can you summarize another regulation of carry or overflow occurring?
1.5 Other Systems for Representing Numbers 1‘s complement(反码) Binary Coded Decimal BCD Floating point
Computerese Computerese, Computer terminology 计算机专业术语 Terms and jargon used in the computer field Technical terms For example, He spoke such a jargon, I couldn’t make head or tail of what he said. Return
Computerese-1 Numeric a. 数字的 Alphabetic a. 字母的 Alphanumeric a.字母数字的 Data type 数据类型 integer 整数,floating-point 浮点数 BCD (Binary-coded decimal) 二进制编码的十进制 ASCII (American Standard Code for Information Interchange) 美国信息交换标准代码
Computerese-2 bit (binary digit) 二进制位,比特 Byte = 8 bits 字节 Word = 2 bytes (16-bit) 字 Double word = 2 words (32-bit) 双字 Quad word = 4 words (64-bit) 4字 Binary 二进制的 Decimal 十进制的 Hexadecimal 十六进制的
Questions and problems: P6. Exercise1.1 2, 4, 5, 8, 9, 14, 15 P8. Exercise1.2 1(a),2(c), 3(e) P14. Exercise1.3 1(a)(e),2(a)(c), 3(b)(d),4(c) (d), 5(c) (a) , 6(a)(7), 7, 8 P20. Exercise1.4 1,3,5,7,9,11,13,12,14