©Brooks/Cole, 2003 Chapter 3 Number Representation.

Slides:



Advertisements
Similar presentations
©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
Advertisements

©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 1.7 Storing Fractions. Excess Notation, continued… In this notation, "m" indicates the total number of bits. For us (working with 8 bits), it.
Floating Point Numbers
Assembly Language and Computer Architecture Using C++ and Java
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Floating Point Numbers
Chapter 3 Number Representation
Number Representation Rizwan Rehman, CCS, DU. Convert a number from decimal to binary notation and vice versa. Understand the different representations.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Simple Data Type Representation and conversion of numbers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Chapter 3 Number Representation. Convert a number from decimal 、 hexadecimal,octal to binary notation and vice versa. Understand the different representations.
Data Representation – Binary Numbers
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
IT253: Computer Organization
Studies in Big Data 4 Weng-Long Chang Athanasios V. Vasilakos MolecularComputing Towards a Novel Computing Architecture for Complex Problem Solving.
Data Representation.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
Chapter 3 Number Representation. Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
CSC 221 Computer Organization and Assembly Language
Number Representation
©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
AEEE2031 Data Representation and Numbering Systems.
Computer Organization and Design Information Encoding II Montek Singh Wed, Aug 29, 2012 Lecture 3.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
SAK Chapter 21 Chapter 2 : Number System 2.1 Decimal, Binary, Octal and Hexadecimal Numbers 2.2 Relation between binary number system with other.
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Binary Arithmetic.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
Department of Computer Science Georgia State University
Data Representation COE 308 Computer Architecture
Lec 3: Data Representation
Data Representation.
William Stallings Computer Organization and Architecture 7th Edition
Data Structures Mohammed Thajeel To the second year students
ECEG-3202 Computer Architecture and Organization
Number Representation
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Chapter 8 Computer Arithmetic
OBJECTIVES After reading this chapter, the reader should be able to :
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
1.6) Storing Integer: 1.7) storing fraction:
Presentation transcript:

©Brooks/Cole, 2003 Chapter 3 Number Representation

©Brooks/Cole, 2003 Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer inside a computer: unsigned, sign-and-magnitude, one’s complement, and two’s complement. Understand the Excess system that is used to store the exponential part of a floating-point number. After reading this chapter, the reader should be able to : O BJECTIVES Understand how floating numbers are stored inside a computer using the exponent and the mantissa.

©Brooks/Cole, 2003 DECIMALANDBINARYDECIMALANDBINARY 3.1

Figure 3-1 Decimal system

©Brooks/Cole, 2003 Figure 3-2 Binary system

©Brooks/Cole, 2003 CONVERSIONCONVERSION 3.2

Figure 3-3 Binary to decimal conversion

©Brooks/Cole, 2003 Example 1 Convert the binary number to decimal. Solution Write out the bits and their weights. Multiply the bit by its corresponding weight and record the result. At the end, add the results to get the decimal number. Binary Weights Decimal 19

©Brooks/Cole, 2003 Example 2 Convert the decimal number 35 to binary. Solution Write out the number at the right corner. Divide the number continuously by 2 and write the quotient and the remainder. The quotients move to the left, and the remainder is recorded under each quotient. Stop when the quotient is zero. 0  1  2  4  8  17  35 Dec. Binary

©Brooks/Cole, 2003 Figure 3-4 Decimal to binary conversion

©Brooks/Cole, 2003 INTEGERREPRESENTATIONINTEGERREPRESENTATION 3.4

Figure 3-5 Range of integers -Integers are whole numbers (i.e. numbers without fraction). An integer can be positive or negative ranges from negative Infinity to 0 (negative integer) and from 0 to positive infinity (positive integer). -No computer can store all the integers in this range because a computer does not have an infinite storage capability. -Therefore, the range of integers depends on the number of bits that a computer allocates to store an integer. This may differ from one computer to another.

©Brooks/Cole, 2003 Figure 3-6 Taxonomy of integers

©Brooks/Cole, 2003 # of Bits # of Bits Range Range ,535 - Unsigned integers are used for counting and addressing - An unsigned integer is an integer without a sign. This means it represents positive integers. - No bit is allocated for the sign. -Range: 0 ….. (2 N – 1) where N is the number of bits allocated to represent an Integer. Table 3.1 Range of unsigned integers Unsigned integers

©Brooks/Cole, 2003 Example 3 Store 7 in an 8-bit memory location. Solution First change the number to binary 111. Add five 0s to make a total of N (8) bits, The number is stored in the memory location.

©Brooks/Cole, 2003 Example 4 Store 258 in a 16-bit memory location. Solution First change the number to binary Add seven 0s to make a total of N (16) bits, The number is stored in the memory location.

©Brooks/Cole, 2003 Table 3.2 Example of storing unsigned integers in two different computers two different computers Decimal Decimal ,760 1,245,678 8-bit allocation overflow 16-bit allocation overflow - Overflow is an error that occurs if one try to store a number that is not within the range defined by the allocation.

©Brooks/Cole, 2003 Example 5 Interpret in decimal if the number was stored as an unsigned integer. Solution Binary Weights Decimal 43

©Brooks/Cole, 2003 There are two 0s in sign-and- magnitude representation: positive and negative. In an 8-bit allocation: +0   Note: Signed integers: Sign and Magnitude

©Brooks/Cole, 2003 Table 3.3 Range of sign-and-magnitude integers # of Bits # of Bits  127  0   0   ,147,483,647 Range

©Brooks/Cole, 2003 In sign-and-magnitude representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive.If it is 1, the number is negative. Note:

©Brooks/Cole, 2003 Example 6 Store +7 in an 8-bit memory location using sign-and-magnitude representation. Solution First change the number to binary 111. Add four 0s to make a total of N-1 (7) bits, Add an extra zero because the number is positive. The result is:

©Brooks/Cole, 2003 Example 7 Store –258 in a 16-bit memory location using sign-and-magnitude representation. Solution First change the number to binary Add six 0s to make a total of N-1 (15) bits, Add an extra 1 because the number is negative. The result is:

©Brooks/Cole, 2003 Table 3.4 Example of storing sign-and-magnitude integers in two computers Decimal Decimal ,760 8-bit allocation overflow 16-bit allocation

©Brooks/Cole, 2003 Example 8 Interpret in decimal if the number was stored as a sign-and-magnitude integer. Solution Ignoring the leftmost bit, the remaining bits are This number in decimal is 59. The leftmost bit is 1, so the number is –59.

©Brooks/Cole, 2003 There are two 0s in one’s complement representation: positive and negative. In an 8-bit allocation: +0   Note: Signed integers: One’s Complement

©Brooks/Cole, 2003 Table 3.5 Range of one’s complement integers # of Bits # of Bits  127  0   0   ,147,483,647 Range

©Brooks/Cole, 2003 In one’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive.If it is 1, the number is negative. Note:

©Brooks/Cole, 2003 Example 9 Store +7 in an 8-bit memory location using one’s complement representation. Solution First change the number to binary 111. Add five 0s to make a total of N (8) bits, The sign is positive, so no more action is needed. The result is:

©Brooks/Cole, 2003 Example 10 Store –258 in a 16-bit memory location using one’s complement representation. Solution First change the number to binary Add seven 0s to make a total of N (16) bits, The sign is negative, so each bit is complemented. The result is:

©Brooks/Cole, 2003 Table 3.6 Example of storing one’s complement integers in two different computers Decimal Decimal       8-bit allocation overflow 16-bit allocation

©Brooks/Cole, 2003 Example 11 Interpret in decimal if the number was stored as a one’s complement integer. Solution The leftmost bit is 1, so the number is negative. First complement it. The result is The complement in decimal is 9. So the original number was –9. Note that complement of a complement is the original number.

©Brooks/Cole, 2003 One’s complement means reversing all bits. If you one’s complement a positive number, you get the corresponding negative number. If you one’s complement a negative number, you get the corresponding positive number. If you one’s complement a number twice, you get the original number. Note:

©Brooks/Cole, 2003 Two’s complement is the most common, the most important, and the most widely used representation of integers today because it has only one representation for 0 and thus does not create confusion in calculation. Note: Signed integers: Two’s Complement

©Brooks/Cole, 2003 Table 3.7 Range of two’s complement integers # of Bits  128  32,768  , ,147,483,647 Range

©Brooks/Cole, 2003 In two’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 1, the number is negative. Note:

©Brooks/Cole, 2003 Example 12 Store +7 in an 8-bit memory location using two’s complement representation. Solution First change the number to binary 111. Add five 0s to make a total of N (8) bits, The sign is positive, so no more action is needed. The result is:

©Brooks/Cole, 2003 Example 13 Store –40 in a 16-bit memory location using two’s complement representation. Solution First change the number to binary Add ten 0s to make a total of N (16) bits, The sign is negative, so leave the rightmost 0s up to the first 1 (including the 1) unchanged and complement the rest. The result is:

©Brooks/Cole, 2003 Table 3.8 Example of storing two’s complement integers in two different computers Decimal Decimal       8-bit allocation overflow 16-bit allocation

©Brooks/Cole, 2003 There is only one 0 in two’s complement: In an 8-bit allocation: 0  Note:

©Brooks/Cole, 2003 Example 14 Interpret in decimal if the number was stored as a two’s complement integer. Solution The leftmost bit is 1. The number is negative. Leave 10 at the right alone and complement the rest. The result is The two’s complement number is 10. So the original number was –10.

©Brooks/Cole, 2003 Two’s complement can be achieved by reversing all bits except the rightmost bits up to the first 1 (inclusive). If you two’s complement a positive number, you get the corresponding negative number. If you two’s complement a negative number, you get the corresponding positive number. If you two’s complement a number twice, you get the original number. Note:

©Brooks/Cole, 2003 Table 3.9 Summary of integer representation Contents of Memory Contents of Memory Unsigned Sign-and- Magnitude  One’s Complement  Two’s Complement 

©Brooks/Cole, Sign and Magnitude and One’s complement representations are not used to store signed numbers by computers today because there are two 0s which confuse programmers. -Sign and Magnitude method is used mainly for applications that do not need operations on numbers (e.g. addition, subtraction,..). For example, changing the analog signals to digital signals. -One’s complement method is interesting for data communication application such as error detection and correction. Summary of integer representation

©Brooks/Cole, 2003 EXCESSSYSTEMEXCESSSYSTEM 3.5 -This representation can be used to store positive and negative numbers but operations on them are very difficult. -It is used mainly to store the exponential value of a fraction. - It depends on a magic number 2 N-1 or 2 N-1 -1

©Brooks/Cole, 2003 Example 15 Represent –25 in Excess_127 using an 8-bit allocation. Solution First add 127 (magic number) to get 102. This number in binary is Add one bit to make it 8 bits in length. The representation is

©Brooks/Cole, 2003 Example 16 Interpret if the representation is Excess_127. Solution First change the number to decimal. It is 254. Then subtract 127 from the number. The result is decimal 127.

©Brooks/Cole, 2003 FLOATING-POINTREPRESENTATIONFLOATING-POINTREPRESENTATION 3.5 -A floating point number contains an integer part and a fraction part. -Integer part is converted to binary as usual but fraction part needs special treatment.

©Brooks/Cole, 2003 Figure 3-7 Changing fractions to binary

©Brooks/Cole, 2003 Example 17 Transform the fraction to binary Solution Write the fraction at the left corner. Multiply the number continuously by 2 and extract the integer part as the binary digit. Stop when the number is   1.5  1.0 

©Brooks/Cole, 2003 Example 18 Transform the fraction 0.4 to a binary of 6 bits. Solution Write the fraction at the left cornet. Multiply the number continuously by 2 and extract the integer part as the binary digit. You can never get the exact binary representation. Stop when you have 6 bits. 0.4  0.8  1.6  1.2  0.4  0.8 

©Brooks/Cole, 2003 Table 3.10 Example of normalization Original Number Original Number Move Move  6  2 6  3  Original Number Original Number     Normalized    x     x    x     x  -Normalization means moving the decimal point so that there is only 1 to the left of the decimal point. -To indicate the original value of the number, multiply the number by 2 e, where e is the number of bits that the decimal Points moved; positive for left and negative for right. Normalization

©Brooks/Cole, 2003 Figure 3-8 IEEE standards for floating-point representation

©Brooks/Cole, 2003 Example 19 Show the representation of the normalized number x Solution The sign is positive. The Excess_127 representation of the exponent is 133. You add extra 0s on the right to make it 23 bits. The number in memory is stored as:

©Brooks/Cole, 2003 Table 3.11 Example of floating-point representation Sign Sign Mantissa Number x x x Exponent Exponent

©Brooks/Cole, 2003 Example 20 Interpret the following 32-bit floating-point number Solution The sign is negative. The exponent is –3 (124 – 127). The number after normalization is x

©Brooks/Cole, 2003 HEXADECIMALNOTATIONHEXADECIMALNOTATION 3.6 -A number such as can be represented in IEEE standard as Or in Hexadecimal notation as x42A32000