Computer Representation of Information

Slides:



Advertisements
Similar presentations
Chapter 2 : Number System
Advertisements

Data Representation Computer Organization &
Data Representation COE 205
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
MOHD. YAMANI IDRIS/ NOORZAILY MOHAMED NOOR 1 Overflow Signed binary is in fixed range -2 n-1  2 n-1 If the answer for addition/subtraction more than the.
1.6 Signed Binary Numbers.
Simple Data Type Representation and conversion of numbers
Computer Arithmetic Nizamettin AYDIN
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
IT253: Computer Organization
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
The Teacher CP4 Binary and all that… CP4 Revision.
CSC 221 Computer Organization and Assembly Language
1 IT 231, CMPE 331 Digital Logic Design Week 2 Number systems and arithmetic.
The Teacher CP4 Binary and all that… CP4 Revision.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
N 3-1 Data Types  Binary information is stored in memory or processor registers  Registers contain either data or control information l Data are numbers.
Lecture 4: Digital Systems & Binary Numbers (4)
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Lecture 6. Fixed and Floating Point Numbers
CS2100 Computer Organisation
Department of Computer Science Georgia State University
Data Representation COE 308 Computer Architecture
NUMBER SYSTEMS.
Data Representation ICS 233
Lec 3: Data Representation
CS2100 Computer Organisation
Data Representation.
A brief comparison of integer and double representation
Dr. Clincy Professor of CS
Lecture No. 4 Number Systems
Number Representation
Dr. Clincy Professor of CS
Standard Data Encoding
Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,
Data Representation Integers
Computer Architecture & Operations I
Number Systems.
University of Gujrat Department of Computer Science
Addition and Substraction
CS1010 Programming Methodology
Data Representation COE 301 Computer Organization
Chapter 2 Bits, Data Types & Operations Integer Representation
Data Representation Data Types Complements Fixed Point Representation
Topic 3 Number Representations and Computer Arithmetics
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Dr. Clincy Professor of CS
Data Representation – Chapter 3
Topic 3 Number Representations and Computer Arithmetics
C1 Number systems.
Number Representation
Storing Negative Integers
CPS120: Introduction to Computer Science
Data Representation ICS 233
ECE 331 – Digital System Design
CSC 220: Computer Organization Signed Number Representation
COMS 361 Computer Organization
1.6) Storing Integer: 1.7) storing fraction:
Data Representation COE 308 Computer Architecture
Two’s Complement & Binary Arithmetic
Presentation transcript:

Computer Representation of Information Time: 90 min.

Outline Representation of Characters Mathematical operations on numbers (addition) Signed integer representation Sign-magnitude notation Two’s complement notation Binary Notations Exercises Real Numbers Representation We will cover …. CSCE 106

Representation of Characters A unique binary pattern/value is used to represent each of the printable characters on your keyboard (e.g. A, a, 4, *, [,’, etc. …), as well as the special control/unprintable characters (e.g. carriage return, line feed, tab, space, etc. …). A byte (8 bits) gives you the opportunity to have 28 (256) unique representations/patterns/values. There are standard character coding schemes to ease interchange of information, e.g. ASCII. The code is designed in such a way not only to preserve uniqueness, but also to keep the order which is often needed in manipulating characters/text, e.g. sorting. The value/pattern used to represent “A” is less by one than the value used to represent “B”, … etc. ASCII (American Standard Code for Information Interchange). CSCE 106

Right-hand Left-hand digit digit 3 4 5 6 7 1 2 8 9 P p 1 A Q a q 2 B R b r C S c s D T d t E U e u F V f v G W g w 8 H X h x 9 I Y i y J Z j z K k L l M m N n O o The slide gives some ASCII character representations in hexadecimal. Appendix A of your book gives the complete ASCII table in decimal. Each base 16 digit corresponds to 4 binary digits. CSCE 106

Mathematical Operations on Numbers (Addition) Most of the mathematical operations on numbers from different number systems are conceptually identical to the decimal arithmetic you are used to. To add two numbers you do the following: Start at the rightmost digit. While there are more digits: Add the current digit of each operand. If the sum is less than the base/radix then record that sum, otherwise record the difference between the sum and the base/radix, and add one to the next digit of operand 1. The slide gives an algorithm for the process of addition. CSCE 106

Mathematical Operations on Numbers (Addition) (cont’d) Decimal numbers: 1610 + 1510 ------ 3110 Start by adding 6 + 5. The sum (11) is not less than the base (10), so (11-10) record 1, and carry 1 by adding it to the first digit of 16, giving 2, then add the next digit from each operand (2+1) to give 3. Octal numbers: 168 + 158 338 Start by adding 6 + 5. The sum (1110) is not less than the base (8), so (11-8) record 3, and carry 1 by adding it to the first digit of 16, giving 2, then add the next digit from each operand (2+1) to give 3. The above discussions can be generalized to any base. CSCE 106

Signed Integers So far, we were representing unsigned integers in binary. We need to have a way for representing the sign of the number (positive or negative). We need to have a sign bit, or figure out some other way, so as to be able to represent negative values as well as positive ones. We will study two notations for representing signed integers: sign-magnitude notation, and two’s complement notation. How can we represent the negative integers in binary? CSCE 106

Sign-Magnitude Notation It leaves the left most bit for the sign (sign bit), and uses the rest of the bits (m - 1) to represent the integer. 0 in the sign bit is used to represent positive values, and 1 is used to represent negative values. Therefore, the range of integer values i which can be represented with m bits is: -(2m-1 – 1) <= i <= +(2m-1 – 1) Using the sign–magnitude notation (in a byte): +2910 is represented as 0001 1101 -2910 is represented as 1001 1101 CSCE 106

Problems with Sign-Magnitude Notation You might find this technique simple, natural, and straight forward, as it closely resembles the way you are used to writing numbers. However this notation creates mainly two problems for the computers: 0 representation (00000000 is not 10000000). Addition of mixed sign numbers (10000101 (–510) and 00000001 doesn’t result in –4). Thus the sign-magnitude notation is not used in computers. You can easily understand that 0 and -0 are the same, but the computer would need additional circuitry to figure this out. The straightforward addition algorithm of mixed sign numbers yields an incorrect result. Addition of a positive and a negative number must be treated as a subtraction problem, and this would need additional logic for the computer to check the sign bits before performing arithmetic. CSCE 106

Two’s Complement Notation Two’s complement of an m-bit number N = (Bitwise/one’s complement of N) + 1 Examples of 8-bit numbers and their 2’s complement representation: +1 = 000000012 –1 = 11111110 + 1 = 11111111 +29 = 000111012 –29 = 11100010 + 1 = 11100011 (2’s complement of 111000112 = 000111002 + 1 = 000111012 (29)) It is the notation used in computers to represent negative numbers. Notice that we still have the sign bit to indicate whether the number is a positive or negative one. You can never read a negative number represented using 2’s complement unless you get its 2’s complement to be able to transform it to decimal unsigned integer. CSCE 106

Two’s Complement Notation (cont’d) For an m-bit signed integer in two’s complement notation, the range of integer values is from –2m–1 to 2m–1 – 1. When m = 8, the range is from –128 to 127. When m = 16, the range is from –32768 to 32767. Two’s complement notation overcomes the problems of sign-magnitude notation. We have only one representation for the 0. Addition of mixed sign integers give correct results (with no need for extra logic). If you add -1 to 1 in two’s complement notation (in 8 bits) you will get 0: 1111 1111 + 0000 0001 1 0000 0000 The rightmost 1 is an overflow, as we use only 8 bits to represent our number, and it is lost. Addition of mixed sign integers are performed in exactly the same way without the need of extra special computer hardware. Adding -5 to +1: 1111 1011 + 1111 1100 (-4 in two’s complement) There are other representations for integers, e.g. BCD (binary coded decimal) system, that we will not study in this course. CSCE 106

Binary Notations Exercises Representations of integers in a byte (8 bits) using different binary notations: Integer Unsigned Sign-magnitude 2's-complement   34 001000102 001000102 001000102 -23 Not Possible 100101112 111010012 -128 Not Possible Not Possible 100000002 310 Not Possible Not Possible Not Possible CSCE 106

Exercises (cont’d) Add (-37) to (25) using 8-bit two’s complement representation. Ans: 2510 -3710 ------ -1210 11 11  Carry 000110012 110110112 ------------- 111101002 + + Remember that you can always check that your answer is correct. CSCE 106

Exercises (cont’d) Subtract (39) from (-17) using 8-bit two’s complement representation. Ans: -1710 3910 ------ -5610 1111111  Carry 111011112 110110012 ------------- 110010002 Final carry overflows 8 bits. - + CSCE 106

Real Numbers Representation Real or Floating-Point Numbers, e.g. 22.625 In binary 101 100 10-1 10-2 10-3 2 . 6 5 decimal point 24 23 22 21 20 2-1 2-2 2-3 1 . binary point CSCE 106

Real Numbers Representation (cont’d) exponent Scientific notation: 2.2625 x 101 Binary scientific notation: 1.0110101 x 24 Hence it consists of a sign bit, a mantissa field, and an exponent field. mantissa exponent mantissa CSCE 106

Next lecture will be about Problem Solving Methods CSCE 106