A brief comparison of integer and double representation

Slides:



Advertisements
Similar presentations
Integers. Integer Storage Since Binary consists only of 0s and 1s, we can’t use a negative sign ( - ) for integers. Instead, the Most Significant Bit.
Advertisements

Faculty of Computer Science © 2006 CMPUT 229 Floating Point Representation Operating with Real Numbers.
1 IEEE Floating Point Revision Guide for Phase Test Week 5.
Booth’s Algorithm.
Number Systems Standard positional representation of numbers:
Computer Science 210 Computer Organization Floating Point Representation.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Binary Number Systems.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Binary Representation and Computer Arithmetic
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
The Binary Number System
Data Representation Number Systems.
Simple Data Type Representation and conversion of numbers
Binary Representation. Binary Representation for Numbers Assume 4-bit numbers 5 as an integer  as an integer  How? 5.0 as a real number  How?
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
IT253: Computer Organization
CSC 221 Computer Organization and Assembly Language
Floating Point in Binary 1.Place Value Chart:
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Data Representation: Floating Point for Real Numbers Computer Organization and Assembly Language: Module 11.
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
William Stallings Computer Organization and Architecture 8th Edition
Floating Point Numbers
Nat 4/5 Computing Science Lesson 1: Binary
Floating Point Representations
Department of Computer Science Georgia State University
Fundamentals of Computer Science
Dr.Faisal Alzyoud 2/20/2018 Binary Arithmetic.
Computer Science 210 Computer Organization
Dr. Clincy Professor of CS
Introduction To Computer Science
Recap Add these numbers together in binary
Data Representation Binary Numbers Binary Addition
Floating Point Math & Representation
Numbers in a Computer Unsigned integers Signed magnitude
April 2006 Saeid Nooshabadi
PRESENTED BY J.SARAVANAN. Introduction: Objective: To provide hardware support for floating point arithmetic. To understand how to represent floating.
William Stallings Computer Organization and Architecture 7th Edition
Chapter 6 Floating Point
Topic 3d Representation of Real Numbers
Luddy Harrison CS433G Spring 2007
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)
Number Representations
Data Representation Data Types Complements Fixed Point Representation
(Part 3-Floating Point Arithmetic)
Computer Science 210 Computer Organization
Arithmetic Logical Unit
Dr. Clincy Professor of CS
ECEG-3202 Computer Architecture and Organization
CS 101 – Sept. 4 Number representation Integer Unsigned √ Signed √
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
How are negative and rational numbers represented on the computer?
Chapter 8 Computer Arithmetic
Storing Integers and Fractions
Representation of real numbers
Recent from Dr. Dan Lo regarding 12/11/17 Dept Exam
Topic 3d Representation of Real Numbers
Floating Point Numbers
Shift registers and Floating Point Numbers
Chapter3 Fixed Point Representation
Numbers with fractions Could be done in pure binary
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Number Representations
1.6) Storing Integer: 1.7) storing fraction:
Today Binary addition Representing negative numbers 2.
Presentation transcript:

A brief comparison of integer and double representation The following slides are accurate for signed data types (can be both positive and negative) We can also make a primitive unsigned by using the unsigned keyword, which effectively increases their range in the positive direction by a power of 2 (1 bit) amwallis

integer 32 bits Range: −2,147,483,648 to 2,147,483,647 i.e. from −231 to 231 − 1 Stored using two’s complement (a special mathematical operation performed on binary numbers)

what is two’s complement? Two’s complement is a method of storing binary numbers that allows negative and positive numbers to be added without any special logic If the number is a positive number then just use that number’s binary representation - nothing needs to be changed If the number is negative, find the complement of it’s binary representation (invert 0's and 1's) Then add 1 to the complement

for example: the decimal number 42 It is represented in binary as: 42 = 1 = 25 + 23 + 21 = 32 + 8 + 2 Since it is positive, nothing needs to be changed – it’s already in it’s two’s complement form!

Now lets look at -42 To start, we take the number 42 in binary: 42 = 1 1 then we take it’s complement (flip the bits)

Now lets look at -42 then we add 1 + -42 in two’s complement form = 1 + 1 -42 in two’s complement form = 1

this makes binary addition very easy for example: 2 + (-1) 2 1 + (-1) 1 = 1 1 Discard the carry

two’s complement cont. Using two’s complement, the first bit will always indicate the sign 1 for negative numbers 0 for positive numbers Which leaves us with 31 bits to represent the value of the integer

double 64 bits Range: −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 But not all numbers in this range can be represented! Represented by: 1 sign bit 11 exponent bits 52 significand bits

double bits visualized For example, 5.5(10) is 101.1(2) in binary Converts to binary scientific notation: 1.011(2) × 22 *note: (10) indicates decimal and (2) binary

double cont. Floating-point representation can't represent all of the numbers in its range — this is impossible 64 bits can represent only 264 distinct values, and there are infinitely many real numbers in the range to represent.

double (8 bit example) To simplify things though – lets take just use only 8 bits to represent our floating point number (instead of the 64 in a double) We use the first bit to represent the sign (1 for negative, 0 for positive), the next four bits for the sum of 7 and the actual exponent (we add 7 to allow for negative exponents), and the last three bits for the mantissa's fractional part.

double (8 bit example) To determine the largest positive number we can represent We would want the sign bit to be 0 We would place 1 in all the exponent bits to get the largest exponent possible We would put 1 in all the mantissa bits. This gives us 0 1111 111, (in our 8 bit example): 1.111(2) × 215 − 7 = 1.111(2) × 28 = 111100000(2)=480(10)

double (8 bit example) Let's consider how to represent 51(10) in this scheme. In binary, this is 110011(2) = 1.10011(2) × 25. When we try to fit the mantissa into the 3-bit portion of our scheme, we find that the last two bits won't fit: We would be forced to round to 1.101(2) ×  25, Resulting in a bit pattern of: 0 1100 101.

double (8 bit example) That rounding means that we're not representing the number precisely. In fact, 1 1100 101 translates to 1.101(2) × 212 − 7 = 1.101(2) × 25 = 110100(2) = 52(10) Thus, in our 8-bit floating-point representation, 51 equals 52!