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



Similar documents
Computer Science 281 Binary and Hexadecimal Review

CSI 333 Lecture 1 Number Systems

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

Useful Number Systems

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

Number Representation

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

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

THE BINARY NUMBER SYSTEM

CS321. Introduction to Numerical Methods

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

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

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

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

Number Systems and Radix Conversion

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

NUMBER SYSTEMS. William Stallings

Positional Numbering System

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

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

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

Lecture 11: Number Systems

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Solution for Homework 2

Chapter 2. Binary Values and Number Systems

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

Lecture 8: Binary Multiplication & Division

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

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

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Lecture 2. Binary and Hexadecimal Numbers

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

Numbering Systems. InThisAppendix...

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

Numerical Matrix Analysis

Systems I: Computer Organization and Architecture

CS201: Architecture and Assembly Language

NUMBER SYSTEMS. 1.1 Introduction

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

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

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

HOMEWORK # 2 SOLUTIO

Chapter 4 -- Decimals

Binary Numbering Systems

Base Conversion written by Cathy Saxton

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

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

Paramedic Program Pre-Admission Mathematics Test Study Guide

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

Today s topics. Digital Computers. More on binary. Binary Digits (Bits)

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

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

Math Circle Beginners Group October 18, 2015

CHAPTER 5 Round-off errors

Binary Numbers. Binary Octal Hexadecimal

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

Binary Adders: Half Adders and Full Adders

The programming language C. sws1 1

Informatica e Sistemi in Tempo Reale

Pemrograman Dasar. Basic Elements Of Java

Continued Fractions and the Euclidean Algorithm

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.

Q-Format number representation. Lecture 5 Fixed Point vs Floating Point. How to store Q30 number to 16-bit memory? Q-format notation.

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Chapter 1: Digital Systems and Binary Numbers

Chapter 4: Computer Codes

Binary Representation

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

DNA Data and Program Representation. Alexandre David

Linear Equations and Inequalities

MATH-0910 Review Concepts (Haugen)

=

Students will benefit from pencils with erasers, if possible since revisions are part of learning.

CPEN Digital Logic Design Binary Systems

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

TCP/IP Drill Pack. By Donna Warren. Created by Donna P. Warren Revised: 1/2/2012 Page 1 of 19

Sources: On the Web: Slides will be available on:

Section 1.4 Place Value Systems of Numeration in Other Bases

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

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

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Preliminary Mathematics

Course Syllabus. MATH 1350-Mathematics for Teachers I. Revision Date: 8/15/2016

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.

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

Figure 1. A typical Laboratory Thermometer graduated in C.

Overview. java.math.biginteger, java.math.bigdecimal. Definition: objects are everything but primitives The eight primitive data type in Java

PREPARATION FOR MATH TESTING at CityLab Academy

5.1 Radical Notation and Rational Exponents

Chapter 1. Binary, octal and hexadecimal numbers

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

Chapter 5. Binary, octal and hexadecimal numbers

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

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

26 Integers: Multiplication, Division, and Order

Transcription:

2/9/9 Binary number system Computer (electronic) systems prefer binary numbers Binary number: represent a number in base-2 Binary numbers 2 3 + 7 + 5 Some terminology Bit: a binary digit ( or ) Hexadecimal notation ( 十 六 進 位 ) 3 2 2 + 2 + 2 + Represents each 4 bits by a single symbol Example: A3 denotes 2 Outline Integer: decimal-binary conversion Integer addition Negative integer (2 s complement representation) Real numbers (floating point representation) Binary to decimal What is the decimal number of b? 2 2 2 2 2 3 2 4 2 5

2/9/9 Decimal to binary What is the binary number of 3 d? Step : Divide the value by 2 and record the remainder Step 2: If quotient is not zero, use the quotient as the new value and repeat step Step 3: The binary representation is the recorded remainders listed from right to left 6 Quotient = 6 Remainder = 3 Quotient = 3 Remainder = Quotient = Remainder = Quotient = Remainder = Algorithm A finite sequence of instructions to describe a systematical method to solve a problem We can represent the decimal-to-binary algorithm by a flow chart It has starting point [step ] Step 2 is a condition statement Step+step 2 is a loop statement The problem size is shrunk after each loop The loop can be terminated [when quotient ==] start n/2 Quotient ==? Yes Arrange the reminders to get the answer Homework: write an algorithm to convert binary to decimal No, let n=quotient 十 進 位 轉 二 進 位 演 算 法 Three algorithms Problem: converting n d to m b. Algorithm : as mentioned in the last class Algorithm 2: m b = For i = to n d m b = m b + Algorithm 3: m b = While n d is not Find 2 k n d <2 k+ m b = m b + 2 k n d = n d 2 k What is the cost of m b = m b +? start What is the cost of finding k? The cost of m b +2 k is just putting at the kth position of m b What is the cost of n d = n d 2 k? n/2 Quotient ==? Yes Arrange the reminders to get the answer No, let n=quotient Recursive algorithm The first algorithm is a recursive algorithm To answer what the binary of 3 d is, you need to answer what the binary of 6 d is. To answer what the binary of 6 d is, you need to answer what the binary of 3 d is. To answer what the binary of 3 d is, you need to answer what the binary of d is. Recursive algorithm Turn a big problem into one or several smaller subproblems Each subproblem is identical to the original one except size Thus, they can be solved by the same method. Need a termination condition. Binary(6) Binary(3) Binary() Binary(3) 2

2/9/9 Integer addition One bit addition What is 5 d +9 d using binary number representation? 5 + 9 4 Another example + Binary number in computer systems Mathematically, a binary integer can have arbitrary number of bits. In computer systems, all data has a limited number of bits. For example, there are different sized (data type) integers char: 8 bits: [, 255] unsigned short: 6 bits: [, 65535] unsigned int: 32 bits: [, 4294967295] Overflow: when adding two integers, the result exceeds the numerical range of the data type Ex: (char) 23+(char) 234 = (char) How about negative integers? We use sign to distinguish positive and negative numbers. In computer system, we can use a bit to present the sign. In a 4 bit integer, for and for -. (sign bit) Good for notation, but difficult for calculation. One bit subtraction - - Example: 4- - - - - - = -*2+*=- 3

2/9/9 Negative integer Can we design a negative number representation such that 4-=4+(-) can be done easily (as easy as addition)? Hint: all number representation in computers has a finite number of bits. If we use 4 bits to represent an integer Zero is, and one is. What is -? Find b 3, b 2, b, b such that b 3 b 2 b b This will be truncated since it is a 4 bits integer Thus, we can use b to represent - d. + Two s complement This number representation is called the two s complement. Algorithm to find the 2 s complement of an integer Step : invert each bit, to and to Step 2: Add. b b ( 6) 6 d = b b -6 d = b b + b b = 6 d b + b b = 6 d truncated Textbook uses a different algorithm, which is used in circuit design + b ( 6) b ( ) Data type b can be d or -6 d. How to tell? Given a bit pattern, one need to specify its data type b is d for unsigned 4 bit int and -6 d for signed 4 bit int In C, there are data types for signed and unsigned integer Data type Number of bits Numerical range char 8 [,255] unsigned short 6 [,65525] short 6 [ 32768, +32767] unsigned int (long) 32 [, 4,294,967,295] int, long 32 [ 2,47,483,648, +2,47,483,647] unsigned long long 64 [, 2 64 ] long long 64 [ 2 63, 2 63 ] 2 s complement to decimal Give a 2 s complement representation, how to know it is a positive number or a negative number? Observe: The left most bit of all positive numbers is, and of all negative numbers is The left most bit of singed data type is called the sign bit Converting 2 s complement to decimal Step: check the sign bit to tell the sign Step 2: If it is a negative number, convert it to its 2 s complement Step 3: Convert the number to decimal and add the sign Step 2 and step 3 are like subroutines, which invoke other algorithms mentioned before. 4

2/9/9 2 s complement addition Examples Another type of overflow What is 5+4 in signed 4 bit representation? 5 d +4 d = b + b = b This is another type of overflow Adding two positive numbers results a negative number; or adding two negative numbers results a positive number. A 4 bits 2 s complement system can only represent 7~ 8 Fraction The binary number of fractions. 5.625 2-3 2-2 2-2 2 2 2 Fraction point To represent a wide range of numbers, we allow the decimal point to float. 4. d = 4. d = 4 d - =.4 d 2 It is just like the scientific notation of numbers.. b = +. b 2 2d = +. b 2 b. This is called the floating point representation of fractions. 5

2/9/9 Coding the value of 2 5 / 8 Sign Exponent 2 5 / 8 Binary representation. Normalization. 2 2 truncated Mantissa Exponent uses excess notation Signed number representations Comparison of 4 bit signed integer representation by sign-bit notation, 2 s complement, and excess notation Sign-bit notation 2 s complement Excess notation 8 7 6 5 4 3 2, - -2-3 -4-5 -6-7 -8 Floating-point numbers In C (and most programming languages), there are two data types for real numbers Data type Size Structure Range Precision float 32 bits Sign: bit Exponent: 8 bits Mantissa: 23 bits double 64 bits Sign: bit Exponent: bits Mantissa: 52 bits ± ~ -44.85 to ~ 38.53 ~ 8 ± ~ -323.3 to ~ 38.3 ~ 6 Truncation error Mantissa field is not large enough 2 5 / 8 = 2.625 2.5 + round off error (.25) Nonterminating representation. = / 6 + / 32 + / 256 + / 52 +... Change the unit of measure Order of computation: 2.5 +.25 +.25 2.5++ =2.5 2.5 + (.25+.25) 2.5+.25=2.75 More in 數 值 分 析 6