16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 ©1995-1999 Barnette ND, McQuain WD, Keenan MA 1 Binary Number System Base.

Slides:



Advertisements
Similar presentations
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Advertisements

Floating Point Numbers
1 IEEE Floating Point Revision Guide for Phase Test Week 5.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Floating Point Numbers
Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or.
Floating Point Numbers. CMPE12cCyrus Bazeghi 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or 2 64.
Assembly Language and Computer Architecture Using C++ and Java
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
M68K Assembly Language Programming Bob Britton Chapter 12 IEEE Floating Point Notice: Chapter slides in this series originally provided by B.Britton. This.
Assembly Language and Computer Architecture Using C++ and Java
Representing Real Numbers Using Floating Point Notation Lecture 6 CSCI 1405, CSCI 1301 Introduction to Computer Science Fall 2009.
Floating Point Numbers
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
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…
The Binary Number System
Data Representation Number Systems.
Simple Data Type Representation and conversion of numbers
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic Programming in C++ Computer Science Dept Va Tech August, 2000 © Barnette ND, McQuain WD, Keenan MA 1 Independent Representation.
IT253: Computer Organization
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 22, 2004 Lecture Number: 24.
Why does it matter how data is stored on a computer? Example: Perform each of the following calculations in your head. a = 4/3 b = a – 1 c = 3*b e = 1.
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.
Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number Columns to the right of the radix have negative.
CSC 221 Computer Organization and Assembly Language
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
How a Computer Processes Information. Java – Numbering Systems OBJECTIVE - Introduction to Numbering Systems and their relation to Computer Problems Review.
Number Systems & Operations
 Lecture 2 Processor Organization  Control needs to have the  Ability to fetch instructions from memory  Logic and means to control instruction sequencing.
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.
Numbers in Computers.
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.7 Instructor: Lin Chen Sept 2013.
Lecture 6: Floating Point Number Representation Information Representation: Floating Point Number Representation Lecture # 7.
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
Learning Objectives 3.3.1f - Describe the nature and uses of floating point form 3.3.1h - Convert a real number to floating point form Learn how to normalise.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
CSCI206 - Computer Organization & Programming
Floating Point Numbers
Nat 4/5 Computing Science Lesson 1: Binary
Department of Computer Science Georgia State University
Fundamentals of Computer Science
Objectives Today: P4 Data Types – Floating Points P4 Variable Quiz P3 Iteration and Selection Practical Are you logged on? Then come around the table Unit.
Binary Fractions.
Computer Science 210 Computer Organization
A brief comparison of integer and double representation
Number Systems and Binary Arithmetic
William Stallings Computer Organization and Architecture 7th Edition
CSCI206 - Computer Organization & Programming
Computer Science 210 Computer Organization
How to represent real numbers
How to represent real numbers
CS 101 – Sept. 4 Number representation Integer Unsigned √ Signed √
Chapter 2: Number Systems
Starter Using the fingers on only one hand, what is the highest number you can count to? Rules: You must start at 1 You must count sequentially (i.e.
Storing Integers and Fractions
Representation of real numbers
COMS 161 Introduction to Computing
Chapter 1 Introduction.
Presentation transcript:

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 1 Binary Number System Base 10 digits: Base 2 digits: 01 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417=4 * * * 10 0 Similarly, in base 2, the digits of a number are just coefficients of powers of the base (2): 1011=1 * * * * 2 0 Any real number can be represented in any base; humans generally use base 10, but computer hardware generally uses base 2 representation.

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 2 Converting from Base 10 to Base 2 The base 10 system is also known as the decimal system; base 2 is referred to as binary. How can we convert an integer from decimal to binary? Here is a simple algorithm: While N > 0 Do Write N % 2// remainder when N is divided by 2 N <-- N / 2// divide N by 2 Endwhile Note that the remainder will always be either 0 or 1, a binary digit or bit. The resulting sequence of bits is the binary representation of the integer N. See the next slide for an example...

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 3 Converting Integers Find the binary representation of the decimal integer N = 23: So the decimal integer N = 23 is represented in base 2 as:10111 Let’s check that: 10111=1*2 4 +1*2 2 +1*2 1 +1*2 0 = =23 Note: we just shifted from base 2 to base 10

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 4 Some Quick Tables Here are some handy facts:

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 5 Converting Fractions How can we convert a fraction from decimal to binary? Here is a simple algorithm: While F != 0 Do Multiply F by 2 Record the “carry” across the decimal point F <-- the fractional part Endwhile Note that the carry will always be either 0 or 1, a binary digit or bit. The resulting sequence of bits is the binary representation of the fraction F. See the next slide for an example...

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 6 Converting Fractions Find the binary representation of the decimal fraction F = : So the decimal fraction F = is represented in base 2 as:.0101 Let’s check that:.0101=1* *2 -4 = =.3125 Note: we just shifted from base 2 to base 10

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 7 Converting a General Decimal Number A general decimal number, like , would be converted to binary by converting the integer and fractional parts separately (as shown earlier) and combining the results. The decimal integer 43 would be represented in binary as: The fractional part.375 would be represented in binary as:.011 So would be represented in binary as:

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 8 Of course, many decimal fractions have infinite decimal expansions. The same is true of binary representation, but there are some (perhaps) surprising differences. Consider the decimal fraction 0.1; how would this be represented in binary? So 0.1 would be represented in binary as: …. Binary Representation and Precision Clearly, this pattern will now repeat forever

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 9 So 0.1 would be represented exactly in binary as: …. What would actually be stored in hardware? Suppose that we have a float variable: float x = 0.1; A float is stored in scientific form (but in binary): …. =( ….) * The exponent is stored using 7 bits and the fractional part is stored using 23 bits (with two bits used for the signs). We cheat and don’t store the first ‘1’, so 0.1 would be stored as: Float Representation That’s -4 in binary Exponent Mantissa (fractional part)

16. Binary Numbers Programming in C++ Computer Science Dept Va Tech August, 1999 © Barnette ND, McQuain WD, Keenan MA 10 So 0.1 would be stored in hardware as: Converting that to decimal, you have the value: That’s fairly close, but not quite equal to, 0.1. This is called storage error, (or conversion error). This is typical. Most real numbers cannot be stored exactly as float s or even as double s. Using a double will improve accuracy since a double stores 53 bits for the mantissa, but there will still be some inevitable storage error. Storage Error