1 Information Representation in Computer Lecture Nine.

Slides:



Advertisements
Similar presentations
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Advertisements

2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Chapter 2: Data Representation
Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
Craig Schock, 2003 Binary Numbers Numbering Systems Counting Symbolic Bases Common Bases (10, 2, 8, 16) Representing Information Binary to Decimal Conversions.
Connecting with Computer Science, 2e
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
Binary Number Systems.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
Binary Representation and Computer Arithmetic
Chapter 5 Data representation.
The Binary Number System
Simple Data Type Representation and conversion of numbers
1 Data Representation Computer Organization Prof. H. Yoon DATA REPRESENTATION Data Types Complements Fixed Point Representations Floating Point Representations.
The character data type char
Digital Design: From Gates to Intelligent Machines
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
IT253: Computer Organization
PHY281Variables operators and math functions Slide 1 More On Variables and Operators, And Maths Functions In this section we will learn more about variables.
Computing Systems Basic arithmetic for computers.
Computer Architecture
Dept. of Computer Science Engineering Islamic Azad University of Mashhad 1 DATA REPRESENTATION Dept. of Computer Science Engineering Islamic Azad University.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer.
Data Representation and Computer Arithmetic
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
CSC 221 Computer Organization and Assembly Language
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
CS 2130 Lecture 23 Data Types.
Systems Architecture, Fourth Edition 1 Data Representation Chapter 3.
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
 Computers are 2-state devices › Pulse – No pulse › On – Off  Represented by › 1 – 0  BINARY.
PRIMITIVE TYPES IN JAVA Primitive Types Operations on Primitive Types.
OCR Computing OGAT Data Types. What OCR need you to know… Data Types a) Primitive data types, integer, real/floating point, character,
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Numbers
Bits, Data Types, and Operations
Chapter 2 Bits, Data Types, and Operations
Machine level representation of data Character representation
Lec 3: Data Representation
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Chapter 2 Data Types and Representations
Floating Point Number system corresponding to the decimal notation
CS1010 Programming Methodology
Data Structures Mohammed Thajeel To the second year students
Chapter 2 Bits, Data Types, and Operations
Chapter 2 Bits, Data Types, and Operations
ASCII Character Codes nul soh stx etx eot 1 lf vt ff cr so
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Cosc 2P12 Week 2.
Number Systems Lecture 2.
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
School of Computer Science and Technology
Introduction to Computer Engineering
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Rayat Shikshan Sanstha’s S. M. Joshi College, Hadapsar
Text Representation ASCII Collating Sequence
DATA REPRESENTATION Data Types Complements Fixed Point Representations
Cosc 2P12 Week 2.
Chapter 2 Bits, Data Types, and Operations
Presentation transcript:

1 Information Representation in Computer Lecture Nine

2 Outline  Everything is a number (in computer, c.f. Pythagoras)  Binary number system  Negative integers  Floating point numbers (reals)  Accuracy and limitation in “computer numbers”  ASCII code for characters  Code for programs, graphics, music, etc

3 Bit, Byte, and Word cont’d A bit is a size that can store 1 digit of a binary number, 0 or 1. A byte is 8 bits, which can store eight 0’s or 1’s. A word is either 32 or 64 bits, depending on computers. Regular PC’s are 32-bit word in size, higher-end workstations are 64-bit. Word size is the size of the registers. What do these bits mean is a matter of interpretation! All information in a computer are represented in a uniform format of bit patterns.

4 Binary Nonnegative Integers Given a 32-bit pattern, e.g., … , it can represent the integer (if you interpret it that way) Note that if we use 32-bit word, the smallest number is 0, and the largest number is , which is = Numbers bigger than this cannot be represented. If such things happen in a calculation, we say it overflowed. Such interpretation is called unsigned int in the programming language C. a 0 lowest bit a 31 highest bit

5 Negative Integers  To represent negative numbers, we’ll agree that the highest bit a 31 representing sign, rather than magnitude, 0 for positive, 1 for negative numbers.  More precisely, all modern computers use 2’s complement representations.  The rule to get a negative number representation is: first write out the bit pattern of the corresponding positive number, complement all bits, then add 1.

6 Property of 2’s Complement Numbers  Two’s complement m of a number n is such that adding it together you get zero (m + n = 0, modulo word size)  Thus m is interpreted as negative of n.  The key point is that computer has a finite word length, the last carry is thrown away.

7 2’s Complement, example  1 in bits is complementing all bits, we get Add 1, we get representation for –1, as Decimal 1 –1 0 Overflow bit not kept by computer

8 2’s Complement, another e.g.  125 in bits is complement all bits, we get Add 1, we get representation for –125, as Decimal 127 – Overflow bit not kept by computer

9 Dual Interpretation of Bit Patterns = = = = = = = = = 128 or = 129 or = 130 or = 131 or = 252 or = 253 or = 254 or = 255 or -1 A byte (or char in C) Unsigned char Signed char

10 Signed and Unsigned Int  If we interpret the number as unsigned, an unsigned integer takes the range 0 to (that is 000…000 to 1111….1111)  If we interpret the number as signed value, the range is –2 31 to (that is 1000….000 to 1111…111, to 0, to 0111….1111).  Who decide what interpretation to take? What if we need numbers bigger than 2 32 ?

11 Addition, Multiplication, and Division in Binary  – – 75=35 74  8 = 9 remainder =56

12 Floating Point Numbers (reals)  To represent numbers like 0.5, , etc, we need to do something else. First, we need to represent them in binary, as E.g for 2+1+1/8+1/16=  Next, we need to rewrite in scientific notation, as 2 1. That is, the number will be written in the form: 1.xxxxxx…  2 e x = 0 or 1

13 Real Numbers on Computer ε Example for β=2, p=3, e min = -1, e max =2 On modern computers the base β is exclusively 2.

14 IEEE 754 standard  The IEEE standard for floating numbers specifies for 32-bit single precision (float in C) as follows:  The highest 31-th bit a 31 is used for sign, 0 for positive, 1 for negative  8 bits, from position 23 to 30, are used to store an integer, for the biased exponent e+127.  The rest 23 bits are used for the significand. signexponentsignificandbit 0 bit 31

15 IEEE Floating Point signexponentsignificandbit 0 a 31 s -1 s -2 s -3 s -23 e0e0 e1e1 e7e7 Bit 31 (a 31 ) specifies the sign Bit 23 to 30 (e 7,e 6,…,e 1,e 0 ), interpreted as an 8-bit unsigned integer, specifies the biased exponent E = e Bit 0 to 22 (s -1,s -2,…,s -22,s -23 ) specifies the fractional part of number in scientific notation. The value of the pattern is: However, the number +0 is a string of all zeros.

16 Example of Floating Point Number signexponentsignificand bit 31 bit The sign is positive, the biased exponent E=127=e+127, so the original exponent e is 0. The significand f is 0. Thus the pattern represents: +( )2 0 = 1.0 signexponentsignificand bit 31 bit The sign is negative, the biased exponent E=126=e+127, so the original exponent e is –1. The significand f =1/2+1/8. Thus the pattern represents: –(1.0 + f)2 -1 = –

17 Encoding to IEEE Format  What is the bit pattern of the real number in IEEE single precision (32-bit) format?  Ans: first, we need to convert the number to binary. We can consider separately the integer 10, and the fractional part For 10, we have 10 = 5 = 2 = 1 = 02 + 1 so = For 0.25, we multiply by 2 (repeatedly) and take the integer part as the digit: 20.25 = 0.5 -> 0 20.5 = 1.0 -> 1 20.0 = 0.0-> 0 So the fractional part is = Thus = = 2 3

in bits  = 2 3  Thus sign is positive, f =.01001, e=3, and E=e+127=130= The bit pattern is signexponentsignificand bit 31 bit fE=e+127

19 IEEE 754 (32-bit) Summary  The bit pattern represents  If e = 0: (-1) s  f   If 0<e<255: (-1) s (1+f) 2 e-127  If e=255 and f = 0: + or - ∞ and f ≠ 0: NaN. … s e f = b b … + b b -1 b -2 b -23

20 Limitations in 32-bit Integer and Floating Point Numbers  Limited range of values (e.g. integers only from –2 31 to 2 31 –1)  Limited resolution for real numbers. E.g., if x is a machine representable value, the next value is x + ε (for some small ε). There is not value in between. This causes “floating point errors” in calculation. The accuracy of a single precision floating point number is about 6 decimal places.

21 Limitations of Single Precision Numbers  Given the representation of the single precision floating point number format, what is the largest magnitude possible? What is the smallest number possible?  With floating point number, it can happen that 1 + ε = 1. What is that largest ε?

22 Double Precision  An IEEE double precision takes twice the number of the bits of the single precision number, 64 bits.  1 bit for the sign  11-bit for exponent  52-bit for significand  The double precision has about 15 decimal places of accuracy

23 Floating Point Rounding Error  Consider 4-bit mantissa floating point addition:  1.010      Shift exponent to that of the large number Round to 4 bits In decimal, it means  6.0

24 Representation of Characters, the ASCII code A B C D E F 0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI 1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 2 SP ! " # $ % & ' ( ) * +, -. / : ; ? A B C D E F G H I J K L M N O 5 P Q R S T U V W X Y Z [ \ ] ^ _ 6 ` a b c d e f g h I j k l m n o 7 p q r s t u v w x y z { | } ~ DEL How to read the table: the top line specifies the last digit in hexadecimal, the leftmost column specifies the higher value digit. E.g., at location (= =65 10 ) is the letter ‘A’.

25 Base-16 Number, or Hexadecimal  Instead of writing out strings of 0’s and 1’s, it is easier to read if we group them in group of 4 bits. A four bit numbers can vary from 0 to 15, we denote them by 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. binary hexadecimal decimal binary hexadecimal decimal A B C D E F 15

26 Program as Numbers  High level programming language C = A + B;  Assembly language add $5, $10, $3  Machine code (MIPS computer) bit 0 bit Not used source 1 source 2 destination not used operation $10$3$5add

27 Graphics as Numbers A picture like this is also represented on computer by bits. If you magnify the picture greatly, you’ll see square “pixels” which is either black or white. These can be represented as binary 1’s and 0’s. Color can also be presented with numbers, if we allow more bits per pixel.

28 Music as Numbers – MP3 format  CD music is sampled 44,100 times per second (44.1 kHertz), each sample is 2 bytes long  The digital music signals are compressed, at a rate of 10 to 1 or more, into MP3 format  The compact MP3 file can be played back on computer or MP3 players

29 Summary  All information in computer are represented by bits. These bits encode information. It’s meaning has to be interpreted in a specific way.  We’ve learned how to represent unsigned integer, negative integer, floating pointer number, as well as ASCII characters.