Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC255-702/703 CTI/DePaul1 CSC-255 Lecture 3 Text and Numerical Storage (Chapter 1 from Brookshear) Modified by Ufuk Verun from Jim Janossy © 2002, DePaul.

Similar presentations


Presentation on theme: "CSC255-702/703 CTI/DePaul1 CSC-255 Lecture 3 Text and Numerical Storage (Chapter 1 from Brookshear) Modified by Ufuk Verun from Jim Janossy © 2002, DePaul."— Presentation transcript:

1 CSC255-702/703 CTI/DePaul1 CSC-255 Lecture 3 Text and Numerical Storage (Chapter 1 from Brookshear) Modified by Ufuk Verun from Jim Janossy © 2002, DePaul University CTI – Chicago and Brookshear © 2003 Pearson Education, Inc.

2 CSC255-702/703 CTI/DePaul2 Resources This PowerPoint presentation is available for download at www.depaul.edu/~uverun/CSC255/fall2002/sl ides/Lecture_03.ppt www.depaul.edu/~uverun/CSC255/fall2002/sl ides/Lecture_03.ppt Textbook: Chapter 1 Print slides at 6 slides/page, avoid waste! Exams are based on slide content, homework and assigned readings

3 CSC255-702/703 CTI/DePaul3 Text Printable characters A, a, B, b, etc. Each different character is assigned a unique 8-bit pattern See the ASCII chart on page 499, Appendix A ASCII: American Standard Code for Information Interchange More recent codings use more bits to store more symbols and characters Unicode for Java, 16 bits per character

4 CSC255-702/703 CTI/DePaul4 ASCII Developed in 1968 originally as a 7-bit code 7 bits can define 128 patterns, 2 7 =128 Extended to 8 bits, 2 8 =256 patterns Most common code in use EBCDIC is analogous IBM mainframe code, 8-bit, different assignment of codes to characters

5 CSC255-702/703 CTI/DePaul5 ASCII Example Text “Hello.” coded in ASCII:

6 CSC255-702/703 CTI/DePaul6 Unicode Developed in 1990’s as a 16-bit code Defines 65,536 patterns, 2 16 Implemented in Java Replaces earlier schemes to support non-English characters (such as Chinese and Japanese alphabets) First 128 characters are same as ASCII

7 CSC255-702/703 CTI/DePaul7 Exercise: ASCII Practice What is “ABCabc” in ASCII? CharHexBits A410100 0001 B420100 0010 C430100 0011 a610110 0001 b620110 0010 c630110 0011

8 CSC255-702/703 CTI/DePaul8 Exercise: More ASCII Practice What is “01234” (“ means characters) in ASCII? CharHexBits 0300011 0000 1310011 0001 2320011 0010 3330011 0011 4340011 0100

9 CSC255-702/703 CTI/DePaul9 ASCII Text Facts Numbers sort before letters Uppercase letters (ABC) sort before lowercase letters (abc) Numbers represented as 8-bit values are inefficient for storage and arithmetic (12,345 takes 5 x 8 = 40 bits, but binary could store it in fewer bits -– 14 bits) All numbers (0 through 9) start with same bits: 0011

10 CSC255-702/703 CTI/DePaul10 Packed Decimal All numbers (0..9) start with same bits 0011 With proper encoding/decoding, there is no need to store the first 4 bits for ASCII number storage Store only the last (unique) 4 bits of each digit, since first 4 bits for numbers are always the same (0011) Takes about half the storage space Where is the sign (+/-) stored?

11 CSC255-702/703 CTI/DePaul11 Exercise: Encoding a Number into Packed Decimal What is “1,234” in ASCII? CharHexBits 1310011 0001 2320011 0010 3330011 0011 4340011 0100 First 4 bits (0011) are the same for all decimal numbers (0 through 9) Only the low-order 4 bits are stored

12 CSC255-702/703 CTI/DePaul12 Encoding into Packed Decimal… What is 1,234 in ASCII? CharHexBits 1310011 0001 2320011 0010 3330011 0011 4340011 0100 Answer: 00010010 00110100

13 CSC255-702/703 CTI/DePaul13 Encoding into Packed Decimal… What is 1,234 in ASCII? CharHexBits 1310011 0001 2320011 0010 3330011 0011 4340011 0100 Answer: 00010010 00110100 Now packed into 2 bytes!

14 CSC255-702/703 CTI/DePaul14 Decoding Packed Decimal Question: What does 00010010 00110100 represent? Someone has to tell you that the bytes contain a number that was stored in packed decimal You have to decode, then interpret it

15 CSC255-702/703 CTI/DePaul15 Decoding Packed Decimal Decoding area is created Number: 00010010 00110100 0011 0011 0011 0011 4 bytes, with leading 0011 generated in each

16 CSC255-702/703 CTI/DePaul16 Decoding Packed Decimal Decoding area is loaded Number: 00010010 00110100 0001 0011 0001 0011 0011 0011 4 bytes, with leading 0011 generated in each

17 CSC255-702/703 CTI/DePaul17 Decoding Packed Decimal Decoding area is loaded Number: 00010010 00110100 0001 0010 0011 0001 0011 0010 0011 0011 4 bytes, with leading 0011 generated in each

18 CSC255-702/703 CTI/DePaul18 Decoding Packed Decimal Decoding area is loaded Number: 00010010 00110100 0001 0010 0011 0011 0001 0011 0010 0011 0011 0011 4 bytes, with leading 0011 generated in each

19 CSC255-702/703 CTI/DePaul19 Decoding Packed Decimal Decoding area is loaded Number: 00010010 00110100 0001 0010 0011 0100 0011 0001 0011 0010 0011 0011 0011 0100 4 bytes, with leading 0011 generated in each

20 CSC255-702/703 CTI/DePaul20 Decoding Packed Decimal Decoding area is interpreted Number: 00010010 00110100 0001 0010 0011 0100 0011 0001 0011 0010 0011 0011 0011 0100 1234

21 CSC255-702/703 CTI/DePaul21 Alternative Number Storages ASCII text: 8-bit “characters” Packed decimal: 4 bits per digit + sign Binary system: base 2 number system Pure binary, positive integers Two’s complement, signed values Excess notation Floating point: sign-exponent-mantissa

22 CSC255-702/703 CTI/DePaul22 Binary System Base 2 number systems Pure binary, positive integers Two’s complement, signed values Excess notation All use bits differently than ASCII Nothing in the bits says whether they are binary coding or ASCII

23 CSC255-702/703 CTI/DePaul23 Number Base Basics The “base” of a number system is defined by how many different digit symbols it uses Decimal is base 10: 0,1,2,3,4,5,6,7,8,9 Binary is base 2: 0,1 Octal is base 8: 0,1,2,3,4,5,6,7 Hex is base 16: 0 thru 9, A,B,C,D,E,F

24 CSC255-702/703 CTI/DePaul24 Number Base Basics … The “value” of each column in a multi- digit number is determined by the number base it is expressed in Example: What is the decimal value of 1101 in decimal, binary, octal, hex?

25 CSC255-702/703 CTI/DePaul25 Number Base 10 - Decimal You figure how much each column is worth, starting from the rightmost column: 10 2 10 1 10 0 100’s 10’s 1’s x x x 1 0 1 base 2 base 1 base 0 Base=10 (decimal)

26 CSC255-702/703 CTI/DePaul26 10 2 10 1 10 0 100’s 10’s 1’s 1 01 Number Base 10 - Decimal x100 x10 x1 1 0 100 101 1x1 0x10 1x100

27 CSC255-702/703 CTI/DePaul27 2 2 2 1 2 0 4’s 2’s 1’s 1 01 Number Base 2 - Binary x4 x2 x1 1 0 4 5 1x1 0x2 1x4

28 CSC255-702/703 CTI/DePaul28 8 2 8 1 8 0 64’s 8’s 1’s 1 01 Number Base 8 - Octal x64 x8 x1 1 0 64 65 1x1 0x8 1x64

29 CSC255-702/703 CTI/DePaul29 16 2 16 1 16 0 256’s 16’s 1’s 1 01 Number Base 16 - Hexadecimal x256 x16 x1 1 0 256 257 1x1 0x16 1x256

30 CSC255-702/703 CTI/DePaul30 Converting from Base 10 to Other Number Bases Convert decimal 1,234 to binary - how? Convert decimal 1,234 to hex - how? Algorithm: 1. Divide number by the new number base 2. Record remainder as low order digit 3. Replace number with division result (quotient) 4. If quotient is not 0, go back to step 1 and repeat

31 CSC255-702/703 CTI/DePaul31 Example: Converting Decimal 1,234 to Binary Low-order digit High-order digit quotientremainder 1234 / 2=6170 617 / 2 =3081 308 / 2 =1540 154 / 2 =770 77 / 2 =381 38 / 2 =19010011010010 19 / 2 =91 9 / 2 =41 4 / 2 =20 2 / 2 =10 1 / 2=01

32 CSC255-702/703 CTI/DePaul32 Example: Converting Decimal 1,234 to Hex 1234 / 16=772 77 / 16 =413=D 4 / 16=04 Low-order digit High-order digit quotientremainder 4D2

33 CSC255-702/703 CTI/DePaul33 Facts about Binary Numbers Pure binary system stores positive integers only 8-bit number = 0 to 255 (2 8 ) 16-bit number = 0 to 65,535 (2 16 ) 32-bit number = 0 to 4,294,967,295 (2 32 ) But no matter how many bits are used, there is always some number too large to be represented

34 CSC255-702/703 CTI/DePaul34 Binary Addition Binary addition facts Used as carry

35 CSC255-702/703 CTI/DePaul35 Binary Addition Addition is as with decimal numbers 1 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 + 1 1 1 0 0 0 1 0 1 1 4 8 7 8 2 2 6 + decimalbinary 1 11 1

36 CSC255-702/703 CTI/DePaul36 Binary Fractions Radix point is like decimal point 1 0 1. 1 0 1 Each column to the right of radix point is worth ½ of column to its left

37 CSC255-702/703 CTI/DePaul37 Binary Fractions

38 CSC255-702/703 CTI/DePaul38 Addition of Binary Fractions Just like normal binary numbers, add from rightmost to leftmost, use carry ½ ¼ 1/81/8 1 2 4 = 2 + ¼ + 1 / 8 = 2.375 = 4 + ½ + ¼ = 4.75 = 7 + 1 / 8 = 7.125 1 1 1. 0 0 1 1 0 0. 1 1 0 0 1 0. 0 1 1 11 +

39 CSC255-702/703 CTI/DePaul39 Exercise: Addition of Binary Fractions ½¼ 1/81/8 124 = decimal ? 0 1 1 0 1 0 1 0. 0 1 1 1 + 0 0 1 0 0 0 1 0. 0 1 1 0 ?? 1 / 16 8163264128


Download ppt "CSC255-702/703 CTI/DePaul1 CSC-255 Lecture 3 Text and Numerical Storage (Chapter 1 from Brookshear) Modified by Ufuk Verun from Jim Janossy © 2002, DePaul."

Similar presentations


Ads by Google