Number Representation

Slides:



Advertisements
Similar presentations
Addition of two binary numbers = = = = 39.
Advertisements

©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 2 : Number System
Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Signed Numbers Up till now we've been concentrating on unsigned numbers. In real life we have to represent signed numbers ( like: -12, -45, 78). The difference.
Signed Numbers.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Chapter 3 Number Representation
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Number System and Codes
Number Representation Rizwan Rehman, CCS, DU. Convert a number from decimal to binary notation and vice versa. Understand the different representations.
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
Review Binary Basic Conversion Binary Decimal
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
3. Representing Integer Data
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
1 Week 3: Data Representation: Negative Numbers READING: Chapter 3.
Simple Data Type Representation and conversion of numbers
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
Chapter 3 Number Representation. Convert a number from decimal 、 hexadecimal,octal to binary notation and vice versa. Understand the different representations.
Representing Integer Data Book : Chapter ( Subject has no point !! ) A99ACF.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Studies in Big Data 4 Weng-Long Chang Athanasios V. Vasilakos MolecularComputing Towards a Novel Computing Architecture for Complex Problem Solving.
Computer Architecture
Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,
Data Representation.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
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.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
THE BINARY SYSTEM.
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.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
D75P 34R - HNC Computer Architecture Week 4 Signed Integers © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen College unless otherwise.
Integers’ Representation. Binary Addition. Two's Complement. Unsigned number representation Binary Addition, Subtraction. Overflow of unsigned numbers.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
Computer Organization 1 Data Representation Negative Integers.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Number Systems Part 2. Counting in Binary DecimalBinary
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Arithmetic James A. Rome Tennessee Governor's Academy August 2010.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Computer Architecture & Operations I
Chapter 4 Operations on Bits.
CHAPTER 9 COMPUTER ARITHMETIC - ALU
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Chapter 3 Data Storage.
Unit 18: Computational Thinking
Number Representation
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
CPS120: Introduction to Computer Science
OBJECTIVES After reading this chapter, the reader should be able to :
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Presentation transcript:

Number Representation CHAPTER 3

3.1 Decimal & binary

Decimal System The position in the decimal numbering system is meaningful The base is 10.

Binary System

Binary System There are only two digits in the binary system 0 and 1. The base is 2. Each position is double the previous position.

3.2 Conversion

Before discussing how numbers in the form of bit patterns stored in memory… 0101101 We should understand how to convert a number from the decimal system to the binary system, and vice versa. 45

Binary to Decimal Conversion

Convert the binary number 10011 to decimal. Example 1 Convert the binary number 10011 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 1 0 0 1 1 Weights 16 8 4 2 1 ------------------------------------- 16 + 0 + 0 + 2 + 1 Decimal 19

Decimal to binary conversion

Convert the decimal number 35 to binary. Example 1 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 Decimal Binary 1 0 0 0 1 1

3.3 Integer Representation

Integer Representation Integer Number: is a whole number without fractions, it can be positive or negative

Integer Representation Integers range between negative infinity (– ∞) and positive infinity (+ ∞) But can a computer store all the integers in between?

Integer Representation Unsigned Signed Sign and Magnitude One’s Complement Two’s Complement

Unsigned Integer Unsigned Integer: is an integer without a sign and ranges between 0 and + ∞

Range: 0  (2N -1) Unsigned Integer Most computers define a constant called the maximum unsigned integer Unsigned integers range between 0 and this constant The maximum unsigned integer depends on the number of bits allocated to represent the unsigned integer in a computer (N) Range: 0  (2N -1)

Range ------------------------------------- Unsigned Integer # of Bits --------- 8 16 Range ------------------------------------- 0 255 0 65,535 Table 3.1 Range of unsigned integers

Unsigned Integer An input device stores an unsigned integer using the following steps: The integer is changed to binary. If the number of bits is less than N, 0s are added to the left of the binary number so that there is a total of N bits.

Example 1 Store 7 in an 8-bit memory location using unsigned representation. First change the integer to binary, (111)2. Add five 0s to make a total of N (8) bits, (00000111)2. The integer is stored in the memory location. Solution

Store 258 in an 16-bit memory location using unsigned representation. Example 2 Store 258 in an 16-bit memory location using unsigned representation. First change the integer to binary (100000010)2. Add seven 0s to make a total of N (16) bits, (0000000100000010)2. The integer is stored in the memory location. Solution

Try to store an unsigned integer Such as 256 in an 8-bit memory What will happen if you Try to store an unsigned integer Such as 256 in an 8-bit memory Location ? Overflow occurs if the decimal is out of range (if binary bits > n )

Unsigned Integer Table 3.2 Example of storing unsigned integers in two different computers Decimal ------------ 7 234 258 24,760 1,245,678 8-bit allocation ------------ 00000111 11101010 overflow 16-bit allocation ------------------------------ 0000000000000111 0000000011101010 0000000100000010 0110000010111000 overflow

representation in decimal? Interpretation How do you interpret an Unsigned Binary representation in decimal?

the binary integer is converted to the unsigned integer 43 Example 3 Interpret 00101011 in decimal if the number was stored as an unsigned integer the binary integer is converted to the unsigned integer 43 Solution

Unsigned Integer Applications Counting : you don’t need negative numbers to count and usually start from 0 or 1 going up Addressing: sometimes computers store the address of a memory location inside another memory location, addresses are positive numbers starting from 0

Integer Representation Unsigned Signed Sign and Magnitude One’s Complement Two’s Complement

Sign-and-magnitude representation Signed Integer: is an integer with a sign either + or -

Sign-and-magnitude representation Storing an integer in a sign-and-magnitude format requires 1(the leftmost) bit to represent the sign (0 for positive and 1 for negative) Range : 0  -(2N-1 -1)…. +(2N-1 -1)

Sign-and-magnitude representation Table 3.3 Range of sign-and-magnitude integers # of Bits ---------- 8 16 32 Range ------------------------------------------------------- -127 -0 -32767 -0 -2,147,483,647 -0 +0 +127 +0 +32767 +0 +2,147,483,647

Sign-and-magnitude representation There are two 0s in sign-and-magnitude representation: positive and negative. In an 8-bit allocation: +0  00000000 -0  10000000

Sign-and-magnitude representation Storing sign-and-magnitude signed integer process: The integer is changed to binary, (the sign is ignored). If the number of bits is less than N-1, 0s are added to the left of the number so that there will be a total of N- 1 bits . If the number is positive, 0 is added to the left (to make it N bits). But if the number is negative, 1 is added to the left (to make it N bits)

Example 4 Store +7 in an 8-bit memory location using sign-and- magnitude representation. The integer is changed to binary (111). Add 4 0s to make a total of N-1 (7) bits, 0000111 . Add an extra 0 (in bold) to represent the positive sign 0 0000111 Solution

Add an extra 1 because the number is negative. Example 5 Store –258 in a 16-bit memory location using sign- and-magnitude representation First change the number to binary 100000010. Add six 0s to make a total of N-1 (15) bits, 000000100000010. Add an extra 1 because the number is negative. 1 000000100000010 Solution

------------------------------ Table 3.4 Example of storing sign-and-magnitude integers in two computers Decimal ------------ +7 -124 +258 -24,760 8-bit allocation ------------ 00000111 11111100 overflow 16-bit allocation ------------------------------ 0000000000000111 1000000001111100 0000000100000010 1110000010111000

representation in decimal? Interpretation How do you interpret a Signed Binary representation in decimal?

Sign-and-magnitude Interpretation Ignore the first (leftmost) bit Change the N -1 bits from binary to decimal Attach a + or – sign to the number based on the leftmost bit.

Example 6 Interpret 10111011 to decimal if the number was stored as a sign-and-magnitude integer. Ignoring the leftmost bit, the remaining bit are 0111011. This number in decimal is 59. the leftmost bit is 1 so the number is – 59. Solution

Signed Integer Applications The sign-and-magnitude representation is not used now by computers because: Operations: such as subtraction and addition is not straightforward for this representation. Uncomfortable in programming: because there are two 0s in this representation

Signed Integer Applications However.. The advantage of this representation is: Transformation: from decimal to binary and vice versa which makes it convenient for applications that don’t need operations on numbers Ex: Converting Audio (analog signals) to digital signals.