1 / 71

Fundamentals of CS Lecture3 Representing Text and image Dr Dalia Sayed

Fundamentals of CS Lecture3 Representing Text and image Dr Dalia Sayed. Outline. Representing Textual Data * ASCII * UNICODE Representing Images. DECIMAL TO OCTAL CONVERSION Conversion of 125 10 to octal. 8 125. r em a in der. 5 7 1. 8 15. 1. 8. 0. 125 10 = 175 8.

tevis
Download Presentation

Fundamentals of CS Lecture3 Representing Text and image Dr Dalia Sayed

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fundamentals of CSLecture3Representing Text and image Dr Dalia Sayed

  2. Outline • Representing Textual Data * ASCII * UNICODE • Representing Images

  3. DECIMAL TO OCTALCONVERSION • Conversion of 12510 tooctal 8125 remainder 5 7 1 8 15 1 8 0 12510 =1758 22

  4. DECIMAL TO HEXACONVERSION • Conversion of 45010 tohexadecimal 16450 remainder 2 12 1 1628 16 1 0 45010 =1C216 22

  5. CONVERSIONOFRATIONALNUMBERS BINARY Example1: DECIMAL 0.812510 =?2 =0.11012 24 Stop when the fraction becomes 0

  6. FractionPart BINARY Example2: DECIMAL .14579 x 2 0.29158 x 2 0.58316 x 2 1.16632 x 2 0.33264 x 2 0.66528 0.1457910 =?2 x 2 1.33056 etc. =0.001001... • This process is continued until the number of digits have sufficient accuracy. 25

  7. FractionPart OCTAL Example3: DECIMAL

  8. SO, ( Integer part . Fraction part)10 =(?)r =( Integer part conversion. conversion)r Fractionpart Example: 41.687510 =101001.10112 153.51310 =231.4065178

  9. CONVERSIONBETWEENNUMBERSYSTEMS Decimal Octal Binary Hexadecimal

  10. EXAMPLE1:BINARY OCTAL • 23=8 Octal digit = 3 binarydigits 10110001101011.1111000001102 =?8 101 001 11010011 . 111 100 000110 2 6 1 5 3 7 4 0 6 =26153.74068

  11. EXAMPLE2:BINARY HEXA • 24 =16 Hexa digit = 4 binarydigits =10110001101011.111100102 16? 0110 1100 101011. 11110010 2 C 6 B F 2 =2C6B.F216

  12. EXAMPLE 3: OCTAL BINARY 7058 =?2 =1110001012

  13. EXAMPLE 4:HEXA BINARY  10AF16 =?2 1 0 A F 0001 0000 10101111 = 00010000101011112

  14. EXAMPLE 6:OCTAL HEXA 10768 =?16 1 0 7 6 001 000 111 110 E 2 3 =23E16

  15. EXAMPLE 7:HEXA OCTAL 1F0C16 =?8 1 F 0 C 0001 1111 0000 1100 1 7 4 1 4 =174148

  16. IV. Binary Fractions

  17. Decoding the binary representation of 101.101

  18. V. Hexadecimal (base 16) • Binary code is too long in representation. Hex is much shorter. • Converting a binary number to a Hex number is relatively easy • Every 4 bit can convert to a Hex • Problem: we are short of numbers • A-10 B-11 C-12 D-13 E-14 F-15

  19. Lookup table

  20. Example

  21. Reading for this lecture • Computer Science: An Overview Section 1.4 2. External links and sources to help you understand the materials.

  22. How to represent text inside the computer? • “I love computer science” • “I was born on 5 Jan. 1998” • “sqrt (9) = 3” • “لا يؤمن أحدكم حتى يحب لأخيه ما يحب لنفسه”

  23. You are right  • Each character (letter, punctuation, etc.) is assigned a unique bit pattern. • ‘a’ , ‘b’ , ‘c’, etc. • ‘+’, ‘-’ , ‘(‘, ‘)’, ‘%’ , ‘$’ , etc. • ‘1’ , ‘2’ , ‘3’ , ‘4’ , etc. (“5 Ahmed Zewail St.) • But what do we do if every company decided to give its own bit patterns?

  24. You are right again   • ASCII (American Standard Code for Information Interchange) • It is the scheme used to represent characters. • ASCII: Uses patterns of 7-bits to represent most symbols used in written English text • If 8-bits are used, the first bit is always set to 0

  25. ASCII Code • ASCII was first proposed by the American National Standards Institute or ANSI in 1963, and finalized in 1968 as ANSI Standard X3.4. • The purpose of ASCII was to provide a standard to code various symbols ( visible and invisible symbols)

  26. ASCII Table Symbol decimal Binary 7 55 00110111 8 56 00111000 9 57 00111001 : 58 00111010 ; 59 00111011 < 60 00111100 = 61 00111101 > 62 00111110 ? 63 00111111 @ 64 01000000 A 65 01000001 B 66 01000010 C 67 01000011

  27. “Hello.” in ASCII 28

  28. How would I know ? If this is letter H ? Or it is Hexa 48 = Decimal 72 ? They both look the same in memory !! 29

  29. How many characters can ASCII represent? • ASCII code can represent only 128 = 27 characters. • It only represents the English Alphabet plus some control characters. • From (00000000)2 (00)16 • To (01111111)2 (7F)16

  30. Exercise • Use the ASCII table to write the ASCII code for the following: • CS111 • 6=2*3

  31. What do we do with other languages? • ISO developed a number of 8 bit extensions to ASCII, each designed to accommodate a major language group • Each defines a “code page” that uses the undefined space from 128-255 in ASCII, mapping it to various characters. • What is the problem with this approach?

  32. What do we do with other languages? • Unicode is designed to represent the world commonly used languages. • It uses 16 bits or more (or less). • It can encode all characters of live languages. • For compatibility, the first 128 Unicode are the same as the ASCII. • Unicode is a family of encoding methods. There is UTF-8, UTF-16, etc.

  33. https://betterexplained.com/articles/unicode

  34. Exercise • Open a file in notepad • Type “ABC” • Store the file with different encoding each time • ANSI • Unicode (UTF-16 Little Endian) • Unicode Big Endian • UTF-8 • Every time, open it in a hexa editor and see the hexa content.

  35. What happens when I type? • When you type the letter A, the hardware logic built into the keyboard automatically translates that character into the ASCII code 65. • Which is then sent to the computer. • Similarly, when the computer sends the ASCII code 65 to output devices, the output hardware instead draw letter “A” on your screen or your computer.

  36. What happens when I type? Screen W E B Memory RAM Keyboard 42 42 W E B 45 45 57 57 Central Processing Unit

  37. Storage Measures • 1 bit • 1 byte = 8 bits • 1 kb = 210 bytes = 1024 bytes !=1000 • 1 Mb = 1 k k bytes = 210 * 210 bytes • 1 G b = 210 * 210 * 210 bytes • 1 Terab = 210 * 210 * 210 * 210 bytes

  38. Storage Measures • 1 petabyte = 210 * 210 * 210 * 210 * 210 bytes (2 to the 50th power ) • 1 exabyte= 260 • 1 zettabyte = 270 • 1 yottabyte = 280

  39. What do these figures mean? • 1 bit: a binarydecision • 1 byte: a character • 5 Megabytes: The complete works of Shakespeare • 2 Gigabytes: 20 meters of shelved books • 10 Terabytes: The printed collection of the US Library of Congress • 200 Petabytes: All printed material in the whole word. • 5 Exabytes: All words ever spoken by human beings

  40. How can we represent Images? • ?? https://mostafanageeb.com/ https://www.youtube.com/watch?v=OHZyrFlpMVE

  41. How can we represent Images? • We can break it into pixels • The simplest form is black/white • We can represent a pixel by one bit

  42. 2. Image representation • An image can be divided into many tiny squares, called pixels. • Each pixel has a particular colour. • The quality of the picture depends on two factors: • the density of pixels. • The length of the word representing colours. • The resolution of an image is the pixels density. • The higher the resolution the more information the image contains. • 600 x 800 is better than 400 x 600

  43. 2. Image representation • Black and white images • Gray images • Colored images • Bitmap images • Vector images

  44. B&W - Gray – Colored Pictures

  45. Black & White Bitmap Images

  46. Black & White Bitmap Images 111111110000000000000000000000000000000000000000000000000000000000000 000000001110000000000000000000000000000000000000000000000000000000110 000111111111100000000000000000000000000000000000000000000000000000110 001111111111110000000011111000000000000000000000000000000000000000000 000011111111100000000111110000000000000000000000000000000000000000000 000000000000000000001111110000000000000000111110000000000000000000000 000000000000000000001111110000000000000000111111000000000000000000000 000000000000000000001111100000000000000000111111100000000000000000000 000011111110000000001111100000000000000000011110000000000000000000000 000001111111100000001111100000000000000000000000000000000000010000000 000011111111110000001111110000000000000000000000000000000011111110000 000011111111110000001111110000000000000000000000000000000011111110000 000011100011110000001111110000000000000000000000000000000011111111000 000111100001111100001111110000000111100000000011110000000111000111110 000111100000111100001111110000001111100000000111110000000111000111110 001111100001111100001111110000001111100000000011111000001111000011110 001111110000111110000111110000000111110000000011111100001111000011110 001111111111111100000111100000000011110000000001111100001111111111110 000111111111111100000111100000000001111000000001111100001111111111110 001111111111111000000111000000000001111000000000111100011111111111110 000011111111111000001110000000000001111000000000111100000111111111110 000000000000000000001110000000000001111000000000111100000011111111110 000000000000000000000000000000000111110000000001111000000000000011110 000000000000000000000000000000000111100000000111111000000000000111110 000000000000000000000000010000011111100000011111110000000000011111100 000000000000000000000000011111111111001111111111100000011111111111000 000000000000000000000000001111111110000011111111000000001111111110000 000000000000000000000000001111111100000001111110000000000011111110000 000000000000000000000000000000111000000000111000000000000001111000000

  47. Gray Bitmap Images • Each individual pixel (pi(x)ctureelement) in a graphic stored as a binary number • Pixel: A small area with associated coordinate location • Example: each point below is represented by a 4-bit code corresponding to 1 of 16 shades of gray

  48. 4=22 choices 00 (off, off)=white 01 (off, on)=light grey 10 (on, off)=dark grey 11 (on, on)=black = (white) 0 0 = (light grey) 0 1 = (dark grey) 1 0 = (black) 1 1 Example: 2-bit per pixel

  49. Colour representation • Colours are represented with a sequence of bits. • 256 colours – how many bits? • Hint for calculating • To figure out how many bits are needed to represent a range of values, figure out the smallest power of 2 that is equal to or bigger than the size of the range. • That is, find xfor 2 x => 256 • 24-bit colour – how many possible colors? • Hints • 16 million possible colours

More Related