Data Representation PDF
Document Details
Uploaded by AdoringCouplet
Prof. O. R. Vincent
Tags
Summary
This document provides a detailed overview of data representation in computing, covering various number systems (binary, octal, hexadecimal). It explains the conversion between these systems and provides examples, along with a brief discussion about data types such as text, numbers, sound, image, and video. Examples showcasing calculations using different number systems are also included.
Full Transcript
Internal Storage and Data Representation Prof. O. R. VINCENT 1 The Concept of Data Internal Representation - Binary System - Octal Numbering System - Hexadecimal Numbering Character Representation - Binary Addition - One’s complement...
Internal Storage and Data Representation Prof. O. R. VINCENT 1 The Concept of Data Internal Representation - Binary System - Octal Numbering System - Hexadecimal Numbering Character Representation - Binary Addition - One’s complement - Two’s Complement 2 Types of Data Text Number Sound Image Video 3 4 Transforming Data Data Information Knowledge Wisdom 5 Data Representation In digital system, numerical information is usually represented in binary form. The binary form is with digits 0 and 1 called a bit. Bit is an acronym for binary digit. A bit is the smallest piece of information that can be stored and manipulated in a computer. When bits are organised into larger units they are called byte. 6 A Nibble = 4 bits = ½ byte A Word = 16 bits 7 8 9 Conversion from base 10 to base 2 2 58 2 29 r 0 2 14 r 1 2 7 r 0 2 3 r 1 2 1 r 1 2 0 r 1 5810 = 1110102 10 11 Convert 0.85937510 to the corresponding binary fraction. 0.859375 X 2 1.718750 X 2 1.437500 X 2 0.875000 X 2 1.750000 X 2 1.500000 X 2 1.000000 0.85937510 = 0.1101112 12 Conversion from base 2 to 10 Convert 101112 to base 10 Solution: 1 0 1 1 1 4 3 2 1 0 Digit Position L R 101112 = 1 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 1 x 20 = 16 + 0 + 4 + 2 + 1 = 2310 13 Convert 1101.00112 to decimal Soln: 1 1 0 1. 0 0 1 1 3 2 1 0 -1 -2 -3 -4 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20. 0 x 2-1 + 0 x 2-2 + 1 x 2-3 + 1 x 2-4 = 8 + 4 + 0 + 1. 0 + 0 + 0.125 + 0.0625 1101.00112 = 13.187510 14 Octal Numbering System - They are numbers in base eight - Takes some eight numbers between 0 – 7 - ease of conversion - Can be used as short hand for binary numbers 15 Conversion table for Octal System Decimal Binary representation in Octal 0 000 1 001 2 010 3 011 4 100 5 101 6 110 7 111 16 The digit position in octal form is 8 8 8. 8 8 8 2 1 0 -1 -2 -3 Digit Position Convert 4238 to decimal 4 2 38 2 1 0 = 4 x 8 2 + 2 x 8 1 + 3 x 80 = (4 x 64) + 2 x 8 + 3 x 1 = 256 + 16 + 3 4238 = 27510 17 Convert 24.68 to binary NB: steps involved (i) convert to decimal (ii) then convert to binary 2 x 8 1 + 4 x 8 0. 6 x 8 -1 16 + 4. 6/8 = 20.7510 (ii) Convert 20.7510 to binary 18 2 20 2 10 r 0 2 5 r 0 2 2 r 1 2 1 r 0 2 0 r 1 19 Ans: 24.68 = 10100.112 0.7510 to 2 0. 7 5 X 2 1. 5 0 X 2 1. 0 0 20 Convert 21610 to octal 8 216 8 27 r 0 8 3 r 3 8 0 r 3 21610 = 3308 21 22 Decimal To Hexadecimal Convert 13210 to hexadecimal 16 132 16 8 r 4 16 0 r 8 13210 = 8416 or 84h 23 Convert 84h to decimal 1 0 8 x 16 + 4 x 16 = 128 +4 = 13210 24 Convert 2AFh to decimal 2 1 0 (2 x 16 ) + A x 16 ) + (F x 16 ) = 2 x 256 + 10 x 16 + 15 x 1 = 512 +160 + 15 2AFh = 68710 25 Hexadecimal to binary 9A2h to binary 9 = 10012 A= 10102 2 = 00102 9A2h = 1001101000102 26 Convert B2Fh to Octal B2Fh B =10112 2 =00102 F = 11112 B2Fh= 101 100 101 1112 = 54578 27 28 29 Computer Arithmetic The arithmetic and logic unit of the central processor in a computer performs all its arithmetic by addition and shifting. Binary addition 810 10002 +710 01112 1510 11112 30 Binary multiplication 510 X 210 510 - 1 0 12 X 210 - 0 1 02 0 0 0 1 0 1 0 0 0 1010= 0 1 0 1 02 31 Binary Division 810/410 = 210 10002/1002 = 102 32 FLOATING POINT ARITHMETIC In computing, floating point describes a system for representing real numbers which supports a wide range of values. Numbers are in general represented approximately to a fixed number of significant digits and scaled using an exponent. 33 34 Representing Negative Numbers Negative numbers are represented by flipping the numbers one at a time. The leftmost bit gives the sign of the number If the leftmost bit is 0, the number is positive When it is 1, the number is negative In practice, a computer calculates one’s complement by inverting the number’s digits. One’s and two’s complements are ways of representing negative numbers in binary 35 36 One’s Complement The one’s complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number (swapping 0s for 1s and vice versa). The one’s complement of the number then behaves like the negative of the original number in some arithmetic operations. 37 One’s Complement To get one’s complement of a number, simple invert each bit. For example, Find the one’s complement of 01001001. 0 1 0 0 1 0 0 1 1’s compl 1 0 1 1 0 1 1 0 38 Using one’s complement, subtract 15 from 26. Soln: 26 - 15 = + 26 + (-15) Binary of 26 = 0 1 1 0 1 0 Binary of 15 = 0 0 1 1 1 1 Inverse = 1 1 0 0 0 0 Add 26 = + 0 1 1 0 1 0 Overflow bit 1 0 0 1 0 1 0 Add overflow bit + 1 0 0 1 0 1 12 = 1110 39 Two’s Complement To get the two’s complement, (i) add 1 to the one’s complement For example: Find the two’s complement of 9. Soln: Decimal value of number: 9 Binary value of number : 1 0 0 1 One’s complement :011 0 Two’s complement :011 1 Decimal value of 2’s complement of 9 = - 9 40 Adv. of using 2’s Complement It can be used in addition and subtraction without the use of bit for the sign of the value. Example: Perform this operation 5 + (-9) = -4 1 1 1 Carry 5 = 0 1 0 1 + -9 = + 0 1 1 1 -ve Sign 1 1 0 0 NT: that the result is in two’s complement representing -4 which is the answer to the original decimal Addition 41 Calculating -3 in two Complement -3 = - (+3) + 3 = 11 0 0 1 1 One’s comp. 1 1 0 0 Add 1 + 1 -3 in two’s Compl = 1 1 0 1 42 43 Example 2:Subtract 18 from 25 using two’s complement 2510 - 1810 = 710 Steps involved: (i) convert 18 to binary (ii) find the one’s complement of the binary equivalent (iii) Add 1 to the one’s complement to change it to two’s complement (iv) Add the result to 25 in binary 44 (i) Convert 18 to binary 2 18 2 9 r 0 2 4 r 1 2 2 r 0 2 1 r 0 0 r 1 18 = 100102 45 (ii) & (iii) Find the one’s complement of 18 = 100102 and Add 1 Decimal 18 Binary Equi. 1 0 0 1 0 One’s Compl. 0 1 1 0 1 Add 1 + 1 Two’s Compl. 0 1 1 1 0 46 (iv) Add the result to 25 in binary 25 = 0 1 1 0 0 1 +0 0 1 1 1 0 Parity Bit 1 0 0 1 1 1 b 47 CHARACTER CODES Character code is a type of code where group of binary is used to represent each character. Character includes digit (0-9), letter (A-Z) and marks such as (semicolon, colon, comma, quotation mark, blanks, etc.) 48 There are types of codes; character code that are commonly used include - Binary coded decimal (BCD) - ASCII code - EBCDIC Code 49 BCD represents decimal numbers by coding each decimal separately into four bits. Example: The binary representation of decimal number 236 is 11101100 while The 4-bit BCD of 236 = 2 3 6 0010 0011 0110 The 4-bits BCD representation requires more bit positions BCD code keeps tracks of each decimal digit. 50 51 ASCII Code American Standard Code for Information Interchange is a standard code developed in the early 1960s. It is being used in small computers, terminals, peripherals and communication devices. ASCII code used seven bits to represent each characters. Seven bits give us 27 = 128. ASCII can represent 128 characters. It is enough to represent the upper and lower case letters, digits, the punctuation marks and a small number of special signs. ASCII code with 7-bits uses three zone bits and four numeric bits to represent characters. ASCII code with 8-bits adds one bit as parity checking. 52 53 Zone bit Numeric bits 000 001 010 011 100 101 110 111 8 4 2 NUL DLE Space 0 @ P \ p 0 0 0 SOH DCI ! 1 A Q a q 0 0 0 STX DC2 " 2 B R b r 0 0 1 ETX DC3 # 3 C S c s 0 0 1 EOT DC4 $ 4 D T d t 0 1 0 ENQ NAK % 5 E U e u 0 1 0 ACK SYN 8 6 F V f v 0 1 1 BEL ETB / 7 G W g w 0 1 1 BS CAN ( 8 H X h x 1 0 0 HT EM ) 9 I Y h y 1 0 0 LF SUB * : J Z j z 1 0 1 VT ESC + ; K [ k { 1 0 1 FF fs ) < L \ l / 1 1 0 CR GS - = M ] m } 1 1 0 SO RS. > N ^ n ~ 1 1 1 SI US / ; O - o DEL 1 1 1 54 For Example A= zone bit Numeric 100 0001 = 65 a= 110 0001 = 97 55 EBCDIC code The name stands for Extended Binary Coded Decimal Interchange Code. IBM developed this code for use on its computers. In EBCDIC 8 bits represent each character. Eight bits gives us 28 = 256. In EBCDIC 256 characters can be represented. This is twice of ASCII. IBM minicomputers and mainframe computers and some mainframe computers that are similar to IBM, use the EBCDIC code. The eight bits can be divided into two zones - Zone bit and numeric bit which both have four bits each. 56 The EBCDIC representation can be summarized as follows: Characters Zone bits Numeric Bits 0-9 1111 0000 - 1001 A-I 1100 0001- 1001 J-R 1101 0001 - 1001 S-Z 1100 0001 - 1000 57 Example: 37 in EBCDIC Zone bit Numeric bit 3 1111 0011 7 1111 0111 = 1111001111110111 37 require a total of sixteen bits. 58 Files and RECORDS What is a file? What are Records? The With Keyword Passing Records as Arguments Arrays of Records Binary Files and Records 28/03/2024 Records 59 FILES We frequently use files for storing information which can be processed by programs. In order to store information permanently and retrieve it we need to use files. Things to note: reaction of a file, storing Information in a file and reading the data present in the file. 28/03/2024 60 A record is a basic data structure. A record is a collection of fields, possibly of different data types, typically in fixed number and sequence. The fields of a record may also be called members, particularly in object- oriented programming. Fields may also be called elements. 28/03/2024 61 DEFINITION The best way to define a record is to include the definition as a part of a variable declaration. This allows us to declare an individual record-type variable, just as we declared simple-type variables and array type variables. The general form of a record-type variable declaration is VAR record name: Record field 1; field 2;... field n END Where field 1 represents the first field declaration, field 2 represents the second field declaration and so on. 28/03/2024 What are records? 62 3 Each field declaration is written in a name that is similar to an individual variable declaration, that is Field name: type Where field name is an identifier that represents the name of the field, and type is the data type of the data item that will occupy the field. Note here that individual fields within the record are separated by semicolons. 28/03/2024 What are records? 63 Example 1:1 Suppose a customer record consists of an integer- type field called customer number, a customer account designation which is of type char, and a customer balance which is a real number. We can represent the customer record with a record-type variable called customer. The variable declaration is as follows: 1.FILE *fptr; 2.char name; 4.float salary; 3.int age; Example of a record 64 28/03/2024 A record is therefore, a special type of data structure that, unlike arrays, collects different data types that define a particular structure such as book, product, person and many others. The programmer defines the data structure under the Type user definition. Let us take the case of defining a book using a record data structure. The main entities of a book are its title, author, unique ISBN number and its price. 28/03/2024 65 What are records? Type Str25 = String; TBookRec = Record Title, Author, ISBN : Str25; Price : Real; End; Var myBookRec : TBookRec; 28/03/2024 66 Another Example Records are distinguished from arrays by the fact that their number of fields is typically fixed, each field has a name, and that each field may have a different type. A record type is a data type that describes such values and variables. Most modern computer languages allow the programmer to define new record types. 28/03/2024 67 DATA PROCESSING TECHNIQUES Data processing systems make use of one or more processing techniques, depending on the requirements of the application. The methods can be categorised according to the ways in which data is controlled, stored and passed through the system; the major categories are: batch processing; on-line processing, which includes real-time and time-sharing; distributed processing and centralised processing. 68 Batch Processing The Batch processing method process batches of data at regular interval. It closely resembles manual methods of data handling, in that transactions are collected together into batches, sent to the computer centre, sorted into the order of the master file and processed. Such systems are known as traditional data processing systems. It has advantage of providing many opportunities for controlling the accuracy of data and conversely, the disadvantage is the delay between the time of collecting transaction and that of receiving the result of processing. 69 On-line Processing System On-line processing systems are those where all peripherals in use are connected to the CPU of the main computer. Transactions can be keyed in directly. The main advantage of an on-line system is the reduction in time between the collection and processing of data. The two main methods of on-line processing are real time and time-sharing processing. 70 Real-time processing This refers to situation where event is monitored and controlled by a computer. For example a car's engine performance can be monitored and controlled by sensing and immediately responding to changes in such factors like the air temperature, ignition timing or engine load. Microprocessors dedicated to particular functions are known as embedded system. 71 Time Sharing This refers to the activity of the computer's processor in allocating time-slices to a number of users who are given access through terminals to centralised computer resources. The aim of the system is to give each user a good response time. The processor time-slice is allocated and controlled by time-sharing operating system. 72 Distributed Processing As the term suggests, a distributed processing system is one which spreads the processing tasks of an organization across several computer system; frequently, these systems are connected and share resources (this may relate to common access to files or programs) through a data communication system. Each computer system in the network should be able to process independently. 73 Centralised System With this type of system, all processing is carried out centrally, generally by a mainframe computer. This is achieved through computer networks. There are several networks that is linked with the central computer where processing takes place. 74 Multitasking While a computer may be viewed as running one gigantic program stored in its main memory, in some systems it is necessary to give the appearance of running several programs simultaneously. This is achieved by having the computer switch rapidly between running each program in turn. One means by which this is done is with a special signal called an interrupt which can periodically cause the computer to stop executing instructions where it was and do something else instead. 75 76 77 78