Introduction to Computer Science Lecture 5 PDF
Document Details
Uploaded by Deleted User
Benha University
Dr. Naglaa Fathy
Tags
Summary
This document is a lecture on Introduction to Computer Science, detailing topics like data representation including ASCII, extended ASCII, Unicode, image and audio representation.
Full Transcript
Introduction to computer science Lecture 5 By Dr. Naglaa Fathy Lecturer, Computer Science Department, Faculty of computers and artificial intelligence, benha university Course Content Course Materials All course material will be made availa...
Introduction to computer science Lecture 5 By Dr. Naglaa Fathy Lecturer, Computer Science Department, Faculty of computers and artificial intelligence, benha university Course Content Course Materials All course material will be made available on: Introduction to Computer Science Google Drive Folder: https://drive.google.com/drive/folders/11c- mUJs4BETD1oBs4H00FEIAlTK3BNyy?usp=sharing Different types of data Text-Based Data Representations ▪The term "character" refers to any symbol that you can normally type on a keyboard (including some symbols that may require multiple key presses to produce). ▪Character set frequently used includes: alphabets: ‘A’.. ‘Z’, and ‘a’.. ‘z’ digits: ‘0’.. ‘9’ special symbols: ‘$’, ‘.’, ‘,’, ‘@’, ‘*’, … non-printable: enter… 6 Text-Based Data Representations Text-based data is represented by binary coding systems namely ASCII – American Standard Code for Information Interchange Extended ASCII EBCDIC – Extended Binary-Coded Decimal Interchange Code (not used anymore, used to be used in IBM mainframes) Unicode These codes are used to represent all characters that can appear in text data such as numbers, letters, and special characters and symbols like $, ! ,% ,… ASCII In ASCII codes each code is made of 7 bits. Number of possible codes M = 27 = 128 codes. Bit-patterns ranging from 0000000 to 1111111 The first pattern represents (null character) The last pattern represents (delete character) ASCII ASCII Extended ASCII Is invented to make the bit-pattern length equal to 8 bits (Byte), by adding a bit to the left of the ASCII code representation. Ex. If ASCII code is 1111111 the extended ASCII code is 01111111. Extended ASCII is not used because it is not standardized as each manufacturer has different 8-bits system. Unicode To represent more languages’ character beside English, Unicode is invented. Uses 16-bit pattern enough to represent all world’s languages. Representing Data: Image Representation Image representation methods Bitmap Graphic Image is divided into matrix of pixels. A pixel represents a dot which is the smallest unit of the image. Image resolution depends on the number of pixels in the image. Higher resolution images require larger memory. Once image is divided into pixels, each pixel is given a bit-pattern. The pixel bit-pattern determines the color of the pixel Pixel Color (Black & white) For black and white images, only two bit-patterns are needed, one to represent a black pixel and the other to represent a white pixel. In this case, the length of the pattern could be only one bit, i.e. 1 pattern to represent a black pixel and 0 pattern to represent a white pixel. The rows of patterns are then stored in the memory. Bitmap graphic method of a black-and-white image Pixel Color(gray scale) To represent a gray-scale image of 4 colors (for example) we need to increase the length of bit-pattern representing the pixel to be 2 bits. In this case 11→ black pixel 10→ dark gray pixel 01→ light gray pixel 00→ white pixel Pixel Color(colored pixel) Any visible color could be constructed from the 3 basic colors Red, Green, Blue (RBG) The difference between one color and another depends on the intensity of the RBG colors in the color Therefore, to represent a colored image, each pixel in the image must be represented by 3 different bit-patterns. Each of them represent the intensity of the basic colors. The length of a bit pattern representing each basic color is usually 8 bits Representation of color pixels 1. Vector Graphic Image is decomposed into lines and curves. Each curve and line is represented by a mathematical formula. The mathematical formula is sorted. No bit-patterns are stored For example a line is described by its coordinates, the circle is described by it’s the coordinates of its centre and length of the radius. The advantage of vector representation is that image can be scaled by multiplying the formula by the scale factor without effecting the image resolution as in bitmap representation Representing Data: Audio Representation Audio is sound Sound signal is analog signal The representation of audio signal requires converting analog signal into digital signal (A/D) Audio representation Representing Data:Video Representation Video is a series of images (frame) shown sequentially (one after another) Thus video data representation is basically the representation of images changed with time. Video files are multimedia files Boolean Logic & Logic Gates Boolean algebra Boolean algebra is a mathematical system for the manipulation of variables that can have one of two values. In formal logic, these values are “true” and “false.” In digital systems, these values are “on” and “off,” 1 and 0, or “high” and “low.” Boolean expressions are created by performing operations on Boolean variables. Boolean logic is the basis of all modern computing Common Boolean operators include AND, OR, and NOT. Boolean algebra A Boolean operator can be completely described using a truth table. A truth table is a tabular representation of all the combinations of values for inputs and their corresponding outputs. It is a mathematical table that shows all possible outcomes that would occur from all possible scenarios that are considered factual, hence the name. Truth tables are usually used for logic problems as in Boolean algebra and electronic circuits. No. of possible combination = 2n, where n=number of variables used in a Boolean expression. The AND operation The AND, operation is a binary operation, meaning that it needs two operands c = a AND b The AND operator is also known as a Boolean product. 0*0 = 0 0*1 = 0 1*0 = 0 1*1 = 1 The dot symbol (“.”) used for representing AND operation(a.b). AND operator has an output 1 if all the inputs are 1 otherwise the output is 0. Both a and b must be true for the result to be true 27 Logical AND Examples Ex 1: 11010011 AND 00001111 00000011 Ex 2: 0111 AND 1001 0001 28 The OR operation The OR, operation is also a binary operation with two operands c = a OR b The OR operator is the Boolean sum. 0+0 = 0 0+1 = 1 1+0 = 1 1+1 = 1 The symbol (“+”) used for represent OR operation. OR operator has an output 1 if any of the inputs are 1 otherwise, the output is 0 If either a OR b is true, then the result is true Logical OR Operation To perform the OR operation, take one column at a time and perform the OR operation using the OR table. Ex 1: 10010011 OR 00001111 10011111 Binary Number A: 1010 Binary Number B: 1100 ---------------------- A OR B Result: 1110 30 The Not operation The NOT, operation is a unary operation with only one operand c = NOT(a) NOT operation is use for complementation. The NOT operation is most often designated by an overbar.” NOT operator has an output 1 if input is 0 or output 0 if input is 1. It simply reverses the true or false value of the operand Example. NOT 1 0 1 0 = 0 1 0 1 The XOR operation The XOR, operation is also a binary operation with two operands The XOR (Exclusive OR) operation compares each bit of two binary numbers returns 1 only if the bits are different. If the bits are the same (both 0 or both 1), it returns 0. The exclusive OR. Similar to OR except that it now gives 0 when both its operands are 1. Binary Number A: 1010 Binary Number B: 1100 ---------------------- A XOR B Result: 0110 Logical XOR Examples Ex 1: 10011001 XOR 0 0 0 0 1 1 1 1 10010110 Ex 2: 0111 XOR 0010 0101 33 The XNOR operation The XNOR, operation is also a binary operation with two operands he XNOR (Exclusive NOR) operation is the complement of the XOR operation. It returns 1 if both bits are the same, and 0 if the bits are different. In other words, it outputs 1 when both inputs are either 0 or 1. 1010 XNOR 1100 ------ 1001 Draw the truth table A.B+A A B A.B A.B+A 0 0 0 0 0 1 0 0 1 0 0 1 1 1 1 1 A+B A B A+B A.B+A 0 0 0 1 0 1 1 0 1 0 1 0 1 1 1 0 Draw the truth table (A+B)A A B A B 0 0 1 1 1 0 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 0 AB+B A B AB 0 0 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 Draw the truth table A+BC. A 0 B 0 C 0 BC 0 A+BC 0 0 0 1 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 (A+B)(A+C) A B C (A+B) (A+C) (A+B)(A+C) 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 Thank you