CSI 333 Lecture 1 Number Systems



Similar documents
Useful Number Systems

Lecture 11: Number Systems

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

NUMBER SYSTEMS. William Stallings

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

Computer Science 281 Binary and Hexadecimal Review

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

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

Positional Numbering System

COMPSCI 210. Binary Fractions. Agenda & Reading

Base Conversion written by Cathy Saxton

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

NUMBER SYSTEMS. 1.1 Introduction

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

Section 1.4 Place Value Systems of Numeration in Other Bases

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

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

Lecture 2. Binary and Hexadecimal Numbers

CPEN Digital Logic Design Binary Systems

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

CS321. Introduction to Numerical Methods

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

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

Number Systems and Radix Conversion

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

Chapter 2. Binary Values and Number Systems

Binary Numbers. Binary Octal Hexadecimal

3. Convert a number from one number system to another

Binary, Hexadecimal, Octal, and BCD Numbers

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.

Systems I: Computer Organization and Architecture

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

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Lecture 8: Binary Multiplication & Division

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

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

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

Number Representation

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

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

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

THE BINARY NUMBER SYSTEM

=

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Numbering Systems. InThisAppendix...

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

HOMEWORK # 2 SOLUTIO

CS201: Architecture and Assembly Language

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Solution for Homework 2

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

Chapter 4 -- Decimals

2011, The McGraw-Hill Companies, Inc. Chapter 3

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

The BBP Algorithm for Pi

Binary Adders: Half Adders and Full Adders

Math 115 Spring 2011 Written Homework 5 Solutions

Chapter 4: Computer Codes

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

Paramedic Program Pre-Admission Mathematics Test Study Guide

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

Number Systems. Introduction / Number Systems

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

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

Binary Representation

Multiplication and Division with Rational Numbers

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

CHAPTER 5 Round-off errors

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

Decimal to Binary Conversion

Chapter 1: Digital Systems and Binary Numbers

5.1 Radical Notation and Rational Exponents

NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix:

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

The Answer to the 14 Most Frequently Asked Modbus Questions

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

Memory is implemented as an array of electronic switches

Chapter 5. Binary, octal and hexadecimal numbers

Addition Methods. Methods Jottings Expanded Compact Examples = 15

Number and codes in digital systems

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

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Math Circle Beginners Group October 18, 2015

A Step towards an Easy Interconversion of Various Number Systems

Zeros of a Polynomial Function

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k Design Consultant

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

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

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

Chapter 1. Binary, octal and hexadecimal numbers

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

Data Storage. 1s and 0s

Preliminary Mathematics

A NEW REPRESENTATION OF THE RATIONAL NUMBERS FOR FAST EASY ARITHMETIC. E. C. R. HEHNER and R. N. S. HORSPOOL

Number of bits needed to address hosts 8

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

Verilog - Representation of Number Literals

Logic Reference Guide

Transcription:

CSI 333 Lecture 1 Number Systems 1 1 / 23

Basics of Number Systems Ref: Appendix C of Deitel & Deitel. Weighted Positional Notation: 192 = 2 10 0 + 9 10 1 + 1 10 2 General: Digit sequence : d n 1 d n 2... d 1 d 0 Value : Decimal system: n 1 ( di 10 i) i=0 Base (or Radix) : 10 Digits : 0, 1, 2,..., 9 1 2 / 23

Number Systems (continued) Base r system: Digits : 0, 1,..., r 1 Digit sequence : s n 1 s n 2... s 1 s 0 Value : n 1 ( si r i) i=0 s 0 - - Least significant digit s n 1 - - Most significant digit 1 3 / 23

Number Systems (continued) Common Values for Radix r: r = 2 : Binary - - Digits: 0, 1. r = 8 : Octal - - Digits: 0, 1..., 7. r = 10 : Decimal - - Digits: 0, 1,..., 9. r = 16 : Hexadecimal (Hex) - - Digits: 0, 1,..., 9, A, B, C, D, E, F (where A = 10, B = 11,..., F = 15). Convention: Base written as subscript (e.g. 277 8 ). 1 4 / 23

Converting from any base to Decimal Example 1: Find the decimal value of 277 8. 277 8 = 7 8 0 + 7 8 1 + 2 8 2 = 7 + 56 + 128 = 191 10 Example 2: Find the decimal value of 3F 4 16. 3F 4 16 = 4 16 0 + 15 16 1 + 3 16 2 = 4 + 240 + 768 = 1012 10 1 5 / 23

Converting to Decimal (continued) Example 3: Find the decimal value of 10110 2. Convention in C: 315 - - Decimal 0315 - - Octal 0x315 - - Hex 10110 2 = 2 1 + 2 2 + 2 4 = 2 + 4 + 16 = 22 10 Machine hardware: Uses binary. 1 6 / 23

Example: 1 0 0 0 1 1 0 1 1 1 1 2 = 2157 8 1 7 / 23 Octal and Hexadecimal Number Systems Note: Examples: Each octal digit - - 3 bits Each hex digit - - 4 bits 6 8 = 110 2 C 16 = 1100 2 Converting from Binary to Octal: 1 Moving from right to left, form groups of three bits. (May need to add leading zeros.) 2 Write octal equivalent for each group.

Octal and Hexadecimal (continued) Converting from Binary to Hex: Similar to binary to octal conversion, except that we form groups of 4 bits. Example: 1 0 1 0 1 1 0 1 1 0 1 2 = 56D 16 Converting Octal or Hex to Binary: Express each digit in binary. Examples: 124 8 = 001 010 100 2 194 16 = 0001 1001 0100 2 Note: Octal and hex are short forms for representing binary numbers. 1 8 / 23

Converting from Decimal to Other Bases Example 1: Convert 37 10 to binary. So, 37 10 = 100101 2. Division Quotient Remainder 37 2 18 1 18 2 9 0 9 2 4 1 4 2 2 0 2 2 1 0 1 2 0 1 Remark: In the binary representation, the remainders are written in bottom-to-top order. 1 9 / 23

Converting from Decimal... (continued) Example 2: Convert 844 10 to hex. So, 844 10 = 34C 16. Division Quotient Remainder 844 16 52 12 = C 52 16 3 4 3 16 0 3 Remark: Again, the remainders are written in bottom-to-top order. 1 10 / 23

2 s Complement form for Negative Integers Sign Convention in Binary: Most significant bit = 0 for non-negative integers. Most significant bit = 1 for negative integers. An Algorithm for Finding 2 s Complement Form: 1 Compute the binary representation for the corresponding positive integer. 2 Complement each bit. 3 Add 1. 1 11 / 23

2 s Complement form... (continued) Recall: Binary addition table. Inputs Sum Carry ------ --- ----- 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 1 12 / 23

2 s Complement form... (continued) Problem: Find the 2 s complement representation of 15 using 8 bits. Solution: +15 in 8-bit binary: 0 0 0 0 1 1 1 1 Complement each bit: 1 1 1 1 0 0 0 0 Add 1 : 1 --------------- 1 1 1 1 0 0 0 1 <-- Answer 1 13 / 23

2 s Complement form... (continued) Problem: Find the 2 s complement representation of 64 using 8 bits. Solution: +64 in 8-bit binary: 0 1 0 0 0 0 0 0 Complement each bit: 1 0 1 1 1 1 1 1 Add 1 : 1 1 1 1 1 1 1 <-- Carries --------------- 1 1 0 0 0 0 0 0 <-- Answer 1 14 / 23

2 s Complement form... (continued) Another method for 2 s complement: 1 Start with the binary representation of the positive value. 2 Copy bits from right to left, until the first 1 has been copied. 3 Complement every bit thereafter. Problem: Find the 2 s complement representation of 64 using 8 bits. Solution: +64 in 8-bit binary: 0 1 0 0 0 0 0 0 2 s complement for -64: 1 1 0 0 0 0 0 0 ^ (First 1 copied) 1 15 / 23

2 s Complement form... (continued) Problem: What is the 2 s complement of 00000000? Solution: Given: 0 0 0 0 0 0 0 0 Complement: 1 1 1 1 1 1 1 1 Add 1 : 1 1 1 1 1 1 1 1 <--- Carries --------------- 0 0 0 0 0 0 0 0 <--- Answer (Value = 0) 1 --> Carry out of sign bit (should be ignored) 1 16 / 23

Representing Real Numbers Remark: Unlike integers, some real numbers cannot be represented exactly. Weighted Positional Notation (for Reals): Example: 119.75 10 Integer part: 119 10 Fractional part: 0.75 10 119 10 = 9 10 0 + 1 10 1 + 1 10 2 0.75 10 = 7 10 1 + 5 10 2 1 17 / 23

Representing Reals (continued) General formula for base r: Sequence : s n 1 s n 2... s 1 s 0. s 1 s 2... s p Value : n 1 ( si r i) + i=0 p ( s i r i) i=1 Example 1: Convert 74.26 8 to decimal. 74.26 8 = 4 8 0 + 7 8 1 + 2 8 1 + 6 8 2 = 60 + 0.25 + 0.09375 = 60.34375 10 1 18 / 23

Representing Reals (continued) Example 2: Convert 101.011 2 to decimal. 101.011 2 = 2 0 + 2 2 + 2 2 + 2 3 = 5 + 0.25 + 0.125 = 5.375 10 Example 3: Convert 21.1 3 to decimal. 21.1 3 = 1 3 0 + 2 3 1 + 1 3 1 = 7 + 0.333... (non-terminating) = 7.3 10 1 19 / 23

Decimal to Binary Conversion for Real Numbers Real number: Integer part. Fractional part Method: Example 1: Convert each part separately. Convert 19.125 10 to binary. 19 10 = 10011 2 (decimal to binary for integer part). To convert 0.125 10 to binary: 0.125 2 = 0.25 : d 1 = 0 0.25 2 = 0.5 : d 2 = 0 0.5 2 = 1.0 : d 3 = 1 So, 0.125 10 = 0.001 2. Therefore, 19.125 10 = 10011.001 2. 1 20 / 23

Decimal to Binary for Reals (continued) Example 2: Convert 76.3125 10 to binary. 76 10 = 1001100 2 (decimal to binary for integer part). To convert 0.3125 10 to binary: 0.3125 2 = 0.625 : d 1 = 0 0.625 2 = 1.25 : d 2 = 1 0.25 2 = 0.5 : d 3 = 0 0.5 2 = 1.0 : d 4 = 1 So, 0.3125 10 = 0.0101 2. Therefore, 76.3125 10 = 1001100.0101 2. 1 21 / 23

Decimal to Binary for Reals (continued) Example 3: Convert 0.7 10 to binary. 0.7 2 = 1.4 : d 1 = 1 0.4 2 = 0.8 : d 2 = 0 0.8 2 = 1.6 : d 3 = 1 0.6 2 = 1.2 : d 4 = 1 0.2 2 = 0.4 : d 5 = 0 0.4 2 = 0.8 : d 6 = 0. The part 0110 repeats indefinitely; so, 0.7 10 = 0.10110 2. Later: IEEE Standard for representing real (or floating point) numbers. 1 22 / 23

Suggestions and Questions to Think About Try additional base conversion problems, including those involving real numbers. Try converting negative integers into 2 s complement form. Recall that converting a real number from base 3 to base 10 may lead to a non-terminating representation. Can this happen when we do the following? Convert a real number in base 5 to base 10. Convert a real number in base 10 to base 5. 1 23 / 23