Recall that in base 10, the digits of a number are just coefficients of powers of the base (10):

Similar documents
Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

CSI 333 Lecture 1 Number Systems

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

NUMBER SYSTEMS. William Stallings

Lecture 11: Number Systems

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

CS321. Introduction to Numerical Methods

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

Useful Number Systems

CHAPTER 5 Round-off errors

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Stanford Math Circle: Sunday, May 9, 2010 Square-Triangular Numbers, Pell s Equation, and Continued Fractions

Activity 1: Using base ten blocks to model operations on decimals

Preliminary Mathematics

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Number Representation

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

The string of digits in the binary number system represents the quantity

Base Conversion written by Cathy Saxton

Numbering Systems. InThisAppendix...

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Math Circle Beginners Group October 18, 2015

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Number Systems and Radix Conversion

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Chapter 5. Binary, octal and hexadecimal numbers

Number of bits needed to address hosts 8

THE BINARY NUMBER SYSTEM

Binary Numbering Systems

FAST INVERSE SQUARE ROOT

Computer Science 281 Binary and Hexadecimal Review

Positional Numbering System

Zuse's Z3 Square Root Algorithm Talk given at Fall meeting of the Ohio Section of the MAA October College of Wooster

Systems I: Computer Organization and Architecture

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

Numerical Matrix Analysis

3. Convert a number from one number system to another

Chapter 1. Binary, octal and hexadecimal numbers

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML. By Prashanth Tilleti

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

=

Binary Adders: Half Adders and Full Adders

NUMBER SYSTEMS. 1.1 Introduction

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Negative Exponents and Scientific Notation

26 Integers: Multiplication, Division, and Order

Polynomials. Dr. philippe B. laval Kennesaw State University. April 3, 2005

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Indices and Surds. The Laws on Indices. 1. Multiplication: Mgr. ubomíra Tomková

Addition Methods. Methods Jottings Expanded Compact Examples = 15

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

The BBP Algorithm for Pi

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

NUMBERS & LOGIC. NUMBER SYSTEMS Candidate answers frequently show that they have little understanding of what constitutes a number system.

ADDITION. Children should extend the carrying method to numbers with at least four digits.

6.1 The Greatest Common Factor; Factoring by Grouping

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Exponents, Radicals, and Scientific Notation

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Binary, Hexadecimal, Octal, and BCD Numbers

Solution Guide Chapter 14 Mixing Fractions, Decimals, and Percents Together

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Grade 6 Mathematics Performance Level Descriptors

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers:

Attention: This material is copyright Chris Hecker. All rights reserved.

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

COMPSCI 210. Binary Fractions. Agenda & Reading

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Part 1 Expressions, Equations, and Inequalities: Simplifying and Solving

5.4 Solving Percent Problems Using the Percent Equation

Lecture 8: Binary Multiplication & Division

Decimal to Binary Conversion

Fast Logarithms on a Floating-Point Device

HOMEWORK # 2 SOLUTIO

Maths Workshop for Parents 2. Fractions and Algebra

The gas can has a capacity of 4.17 gallons and weighs 3.4 pounds.

FRACTIONS COMMON MISTAKES

Chapter 2. Binary Values and Number Systems

Review of Scientific Notation and Significant Figures

Logarithmic and Exponential Equations

APPENDIX B. Routers route based on the network number. The router that delivers the data packet to the correct destination host uses the host ID.

Grade 6 Math Circles. Binary and Beyond

Zero: If P is a polynomial and if c is a number such that P (c) = 0 then c is a zero of P.

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Chapter 1: Order of Operations, Fractions & Percents

Number of Divisors. Terms. Factors, prime factorization, exponents, Materials. Transparencies Activity Sheets Calculators

Solving Systems of Two Equations Algebraically

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Lecture 2. Binary and Hexadecimal Numbers

Advanced Tutorials. Numeric Data In SAS : Guidelines for Storage and Display Paul Gorrell, Social & Scientific Systems, Inc., Silver Spring, MD

Computational Models Lecture 8, Spring 2009

1. The Fly In The Ointment

Multiplying Fractions

Transcription:

Binary Number System 1 Base 10 digits: 0 1 2 3 4 5 6 7 8 9 Base 2 digits: 0 1 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417 = 4 * 10 2 + 1 * 10 1 + 7 * 10 0 Similarly, in base 2, the digits of a number are just coefficients of powers of the base (2): 1011 = 1 * 2 3 + 0 * 2 2 + 1 * 2 1 + 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. Converting from Base 10 to Base 2 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...

Converting Integers 3 Find the binary representation of the decimal integer N = 23: Integer Remainder 23 11 1 5 1 2 1 1 0 0 1 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 = 16 + 4 + 2 + 1 = 23 Note: we just shifted from base 2 to base 10 Some Quick Tables 4 Here are some handy facts: Power of 2 Base 2 Base 10 2-4.0001.0625 2-3.001.125 2-2.01.25 2-1.1.5 2 0 1 1 2 1 10 2 2 2 100 4 2 3 1000 8 2 4 10000 16 2 5 100000 32 2 6 1000000 64 2 7 10000000 128 2 8 100000000 256 N Binary 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111

Converting Fractions 5 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... Converting Fractions 6 Find the binary representation of the decimal fraction F = 0.3125: Carry Fraction.3125 0.6250 1.2500 0.5000 1.0000 So the decimal fraction F = 0.3125 is represented in base 2 as:.0101 Let s check that:.0101 = 1*2-2 + 1*2-4 =.25 +.0625 =.3125 Note: we just shifted from base 2 to base 10

Converting a General Decimal Number 7 A general decimal number, like 43.375, 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: 101011 Integer 43 Remainder The fractional part.375 would be represented in binary as:.011 Carry Fraction.375 So 43.375 would be represented in binary as: 101011.011 Binary Representation and Precision 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? Carry Fraction Clearly, this pattern will now repeat forever So 0.1 would be represented in binary as: 0.0 0011 0011 0011 0011..1 0.2 0.4 0.8 1.6 1.2 0.4 0.8 1.6 1.2????

Float Representation 9 So 0.1 would be represented exactly in binary as: 0.0 0011 0011 0011 0011. What would actually be stored in hardware? Suppose that we have a float variable: float x = 0.1; That s -4 in binary A float is stored in scientific form (but in binary): 0.0 0011 0011 0011 0011. =(1.1 0011 0011 0011.) * 2-100 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: -0000100 +.1 0011 0011 0011 0011 0011 00 Exponent Mantissa (fractional part) Storage Error 10 So 0.1 would be stored in hardware as: -0000100 +.1 0011 0011 0011 0011 0011 00 Converting that to decimal, you have the value: 0.0999999940395355 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 floats or even as doubles. Using a double will improve accuracy since a double stores 53 bits for the mantissa, but there will still be some inevitable storage error.