PSU CS 106 Computing Fundamentals II Base Conversion of Integer Numbers HM 4/6/2008.

Slides:



Advertisements
Similar presentations
Base Conversion COP Practice Problem  Print a String in reverse order:  For example, if we want to print “HELLO” backwards,  we first print:
Advertisements

DATA REPRESENTATION CONVERSION.
James Tam Beyond base 10: Non-decimal based number system What exactly is decimal? How do other number systems work (binary, octal and hex) How to convert.
Connecting with Computer Science, 2e
Level ISA3: Information Representation
Number Systems. 2 The total number of allowable symbols in a number system is called the radix or base of the system. Decimal Numbers: radix = 10 (symbols:
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
Data Representation in Computers
1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems.
Converting Binary to Octal
Number Systems and Arithmetic
© Copyright 2000 Indiana University Board of Trustees Proficiency Quiz Study Guide Note: The following slides are provided courtesy of Dr. Bob Orr (Computer.
Binary Numbers.
Data Representation in Computers. Data Representation in Computers/Session 3 / 2 of 33 Number systems  The additive approach – Number earlier consisted.
Hexadecimal Dk Izzati Pg Haji Ahmad.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Number Systems 0, 1 0, 1, 2, 3, 4, 5, 6, 7 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 0, 1, 2, 3,
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
© GCSE Computing Candidates should be able to:  convert positive denary whole numbers (0-255) into 8-bit binary numbers and vice versa  add two 8-bit.
Real Numbers and the Decimal Number System
Binary and Hexadecimal Numbers
PSU CS 106 Computing Fundamentals II Bits, Binary Numbers & Binary Arithmetic HM 1/3/2009.
Simple Data Type Representation and conversion of numbers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Computer Architecture I: Digital Design Dr. Robert D. Kent Lecture 1 – Part B Data, Representation & Numeracy.
Numbering systems.
Number Systems - Part II
Copyright © Cengage Learning. All rights reserved. CHAPTER 2 THE LOGIC OF COMPOUND STATEMENTS THE LOGIC OF COMPOUND STATEMENTS.
Numbering Systems CS208.
1 Problem Solving using computers Data.. Representation & storage Representation of Numeric data The Binary System.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Lecture 2 Bits, Bytes & Number systems
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Number Systems Ron Christensen CIS 121.
CCE-EDUSAT SESSION FOR COMPUTER FUNDAMENTALS Date: Session III Topic: Number Systems Faculty: Anita Kanavalli Department of CSE M S Ramaiah.
Digital Logic Lecture 2 Number Systems
CMSC 104, Lecture 051 Binary / Hex Binary and Hex The number systems of Computer Science.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
AEEE2031 Data Representation and Numbering Systems.
DECIMALBINARY a) b) c) d) e) f) Revision Exercise DECIMALBINARY a) b) c)
Number Representation (Part 1) Computer Architecture (Fall 2006)
ECE DIGITAL LOGIC LECTURE 2: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/14/2016.
CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 2 1Created by: Ms.Amany AlSaleh.
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.
Number Systems and Binary Arithmetic Quantitative Analysis II Professor Bob Orr.
Digital logic COMP214  Lecture 2 Dr. Sarah M.Eljack Chapter 1 1.
Number Systems & Binary Arithmetic
Some basic concepts underlying computer archi­tecture
Appendix F Number Systems binary 0, 1 0, 1, 2, 3, 4, 5, 6, 7
Digital Design Chapter One Digital Systems and Binary Numbers
Numbering Systems.
Data Representation.
Octal to Decimal Decimal Octal Binary Hexadecimal.
Number Systems and Binary Arithmetic
Digital Systems and Number Systems
Positional Notation A positional or place-value notation is a numeral system in which each position is related to the next by a constant multiplier, called.
Convert Decimal to Binary
Number Theory and Cryptography
Chapter 3 Data Representation
Number System conversions
Number Systems and Binary Arithmetic
Numbering System TODAY AND TOMORROW 11th Edition
Digital Electronics and Microprocessors
Chapter 2: Number Systems
Chapter Four Data Representation in Computers By Bezawit E.
William Stallings Computer Organization and Architecture 10th Edition
Decimal / Binary Conversions
COMS 161 Introduction to Computing
Binary, Hexadecimal, and Base 10.
Presentation transcript:

PSU CS 106 Computing Fundamentals II Base Conversion of Integer Numbers HM 4/6/2008

2 © Dr. Herbert G. Mayer Agenda General Conversion Algorithm Digits for Numbers with Base b Power-Series Conversion Decimal to Binary Samples Binary to Decimal Samples Simplest Conversions

3 © Dr. Herbert G. Mayer General Conversion Algorithm The general algorithm for converting a non-negative number N of base b = 10 to a number T of same value but different base t, with t being an integer Summary: –Repeatedly divide N by t and record the remainders modulo t –New number T is the sequence of the remainder digits in reverse order of creation Detail of Algorithm: –This method uses repeated integer division of N by t: –Starting with the absolute value of N, set the initial quotient q = N: –Step 1: perform the next integer division, create the quotient q = q / t, and record the remainder in the range 0.. t-1 –Step 2: Is q = 0? If so, go to step 4 –Step 3: Else repeat step 1 –Step 4: record the remainders from bottom-to-top in left-to-right order. That is the new number T

4 © Dr. Herbert G. Mayer General Conversion Algorithm Example: Convert decimal N = 500 to an equivalent number T of base t = 2: N base 10Quotient N / 10 repeated Remainder base / 2 = / 2 = / 2 = / 2 = / 2 = / 2 = 71 7 / 2 = 31 3 / 2 = 11 1 / 2 = 01 STOP Binary representation of decimal 500 is

5 © Dr. Herbert G. Mayer Digits for Numbers with Base b Digits for Numbers with base b are explained here: Any plausible numeric system using a power-series similar to the decimal system should have a base b > 1. Consequently there may be a need for new digits. In the decimal system we use the digits ‘0’.. ‘9’. If a base b > 10 is chosen, a typical convention is to use additional digits from the Roman alphabet, with digit ‘a’ standing for the value 10, ‘b’ for the value 11 etc. Interestingly, the Babylonian system with base 60 did not use that convention. Instead, this system created 60 different digits via a combination of distinct digits (like the 10 decimal digits) and repetition (like the Roman system, that lists 3 ‘X’ for decimal 30). In the hexadecimal system (base b = 16) the convention is to use letters ‘a’.. ‘f’ for the digits values 10 through 15. Lower- and upper-case letters are used synonymously for convenience.

6 © Dr. Herbert G. Mayer Digits for Numbers with Base b=16 Hexadecimal digitEquivalent decimal values A10 B11 C12 D13 E14 F15

7 © Dr. Herbert G. Mayer Digits for Numbers with Base b=16 Example 1: –symbol 3ba8 is a possible hexadecimal number. The highest power of 16 used in 3ba8 is in the position associated with hex digit ‘3’. Its corresponding numeric value is 16 3, which is 4,096 in decimal. Thus hex digit ‘3’ contributes 3 * 4096 to the total value of the number. The ‘b’ contributes 11 * 16 2, etc. Example 2: –0A01_FFFF is a possible hexadecimal number. The highest power of 16 used in this hex number is the one in the position associated with digit ‘A’. Its corresponding numeric value is 16 6 = 16,777,216 in decimal. –Thus hex digit ‘A’ contributes 10 * 16,777,276 to the total value of number 0A01_FFFF. It could also be written as: a01fff. For numeric systems with bases b < 10 there is no need to invent new digits. A subset of the 10 decimal digits can be used.

8 © Dr. Herbert G. Mayer Digits for Numbers with Base b=20 Should we chose the base b = 20, we’d have to invent 4 more digits. Adding ‘g’ to ‘j’ to hex digits might be plausible, shown below. Base 20 digitsEquivalent decimal values A10 B11 C12 D13 E14 F15 G16 H17 I18 J19

9 © Dr. Herbert G. Mayer Power-Series Conversion General power-series conversion of a number T with a base different from 10 to an equivalent number N with base b = 10. Summary: –Starting with an initial decimal value of 0, for all digits d of T, multiply d by the corresponding power of t, and add to the total decimal result. Detail: –Starting with an initial total value of 0, the initial exponent e = 0 for base t, and the rightmost digit d 0 of T, do the following: –Step 1: set the exponent e = 0, and the total decimal value total = 0 –Step 2: compute t e, multiply d e by t e and add to total –Step 3: increase e by 1 –Step 4: move to the next higher digit d if one is left, and execute step 2; else go to step 5 –Step 5: we are done, all digits have been taken into account, and the decimal value is in total.

10 © Dr. Herbert G. Mayer Power-Series Conversion Example for base 2: binary number is to be converted to decimal: –Tracking the exponents e for the powers of 2 in , there are only 2 contributing binary digits different from 0. –Ignore leading zeros; there is one leading 0 –These 1 digits are at exponents e=1 and e=5 –I.e. 1 * 2 1 which is 2, and 1 * 2 5 which is 32. –Hence the total is = 34. Example for base 16: hexadecimal number 1ba0 is converted to base 10: –Tracking the exponents e for the powers of 16, we see, that there are only 3 contributing hex digits different from 0. –These are at powers 1, 2, and 3 a 16 * 16 1 = a 16 * 16 = 10 * 16 b 16 * 16 2 = b 16 * 256 = 11 * 256, and 1 16 * 16 3 = 1 16 * 4096 = –Hence the total = 10 * * * 4096 = 7072.

11 © Dr. Herbert G. Mayer Decimal to Binary Samples Decimal NQuotient N / 2Remainder 678 / 2 = / 2 = / 2 = / 2 = / 2 = / 2 = / 2 =50 5 / 2 =21 2 / 2 =10 1 / 2 =01 STOP Algorithmic base conversion works for target base > 10 and < 10. Binary representation of decimal 678 is

12 © Dr. Herbert G. Mayer Decimal to Hexadecimal Samples N = 500 base 10Quotient N / 16 repeatedRemainder base 16 Written in base 10 and / 16 =31 4 = 4 31 / 16 =115 = f 1 / 16 =0 1 = 1 STOP Hexadecimal representation of decimal is 1f4 16

13 © Dr. Herbert G. Mayer Decimal to Hexadecimal Samples Hexadecimal representation of decimal 1, is 68e 16 N = 1678 base 10Quotient N / 16 repeatedRemainder base / 16 = = e 104 / 16 = 6 8 = 8 6 / 16 = 0 6 = 6 STOP

14 © Dr. Herbert G. Mayer Binary to Decimal Samples Binary number converted to decimal, using power- series: –1 * 2 0 = 1 + –1 * 2 1 = 2 + –1 * 2 3 = 8 + –1 * 2 7 = Decimal representation binary is Binary number converted to decimal, using power- series: –1 * 2 1 = 1 + –1 * 2 3 = 2 + –1 * 2 8 = Decimal representation binary is

15 © Dr. Herbert G. Mayer Simplest Conversions Conversion from source base b s to target b t are trivial, whenever one is an integral power of the other This is the case between source base b s = 16 to target base b t = 2 Also between bases b s = 16 and b t = 4 Also between bases b s = 16 and b t = 8 Also between bases b s = 4 and b t = 2 Etc. It is easy to see that in such cases the conversion via numeric computation can be by-passed altogether Instead, the conversion amounts to simply re-writing the digits in expanded or contracted form For example, the hex number 1f 16 rewritten in binary is

16 © Dr. Herbert G. Mayer Simplest Conversions Decimal valueBinary numberBase 4 equivalent _0961_00_00_00_00_00_ Decimal valueBinary numberHexadecimal equivalent = 10_0100_ _0000_0000_0000 = Decimal valueHexadecimal numberBinary equivalent 65,535FFFF1111_1111_1111_1111 4,294,967,295FFFF_FFFF1111_1111_1111_1111_1111_1111_1111_1111 2,748ABC1010_1011_ F41_1111_0100