We say that the base of the decimal number system is ten, represented by the symbol

Similar documents
NUMBERS AND CODES CHAPTER Numbers

CHAPTER 2 NUMBER SYSTEMS

Additive Numbering Systems and Numbers of Different Bases MAT 142 RSCC Scott Surgent

12/31/2010. Digital Operations and Computations Course Notes. 01-Number Systems Text: Unit 1. Overview. What is a Digital System?

Week No. 06: Numbering Systems

Fundamentals of Mathematics I

Binary addition example worked out

Numbering Systems. Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary.

ENGIN 112 Intro to Electrical and Computer Engineering

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

CSEN102 Introduction to Computer Science

of Digital Electronics

Chapter 5. Number Theory. 5.1 Base b representations

Chapter 1. Foundations of GMAT Math. Arithmetic

What are binary numbers and why do we use them? BINARY NUMBERS. Converting decimal numbers to binary numbers

Computer Number Systems

REVIEW Chapter 1 The Real Number System

Beyond Whole Number Bases

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

Trinity Web Site Design. Today we will learn about the technology of numbering systems.

CSE 241 Digital Systems Spring 2013

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

Mathematics for Health and Physical Sciences

Chapter 1 CSCI

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

Discrete mathematics is the study of techniques, ideas and modes of

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

Why digital? Overview. Number Systems. Binary to Decimal conversion

Number Bases: Dr Olga Maleva

THE LOGIC OF COMPOUND STATEMENTS

ENG2410 Digital Design Introduction to Digital Systems. Fall 2017 S. Areibi School of Engineering University of Guelph

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

Counting in Different Number Systems

Contents. Chapter 2 Digital Circuits Page 1 of 30

Math 302 Module 4. Department of Mathematics College of the Redwoods. June 17, 2011

School of Computer Science and Electrical Engineering 28/05/01. Digital Circuits. Lecture 14. ENG1030 Electrical Physics and Electronics

Conversions between Decimal and Binary

1.2 Algebraic Expressions and Sets of Numbers

Math 016 Lessons Wimayra LUY

EXPRESSING NUMBERS IN ENGLISH

CISC 1400 Discrete Structures

Number Bases. Ioan Despi. University of New England. August 4, 2013

Mental Math 5 th Grade

K K.OA.2 1.OA.2 2.OA.1 3.OA.3 4.OA.3 5.NF.2 6.NS.1 7.NS.3 8.EE.8c

You separate binary numbers into columns in a similar fashion. 2 5 = 32

Informatics 1 - Computation & Logic: Tutorial 3

Apply basic properties of real and complex numbers in constructing mathematical arguments (e.g., if a < b and c < 0, then ac > bc)

Four Important Number Systems

STEP Support Programme. Hints and Partial Solutions for Assignment 17

Finding Prime Factors

SWITCH TEAM MEMBERS SWITCH TEAM MEMBERS

Fundamentals of Digital Design

hexadecimal-to-decimal conversion

Number Systems. There are 10 kinds of people those that understand binary, those that don t, and those that expected this joke to be in base 2

Seven is less than 11. Four more than seventeen. Four is not equal to three.

Lecture 2. The Euclidean Algorithm and Numbers in Other Bases

HW: page 168 (12-24 evens, 25-28) Extra Credit # 29 & 31

Math Review. for the Quantitative Reasoning measure of the GRE General Test

ENGIN 112 Intro to Electrical and Computer Engineering

Arithmetic with Whole Numbers and Money Variables and Evaluation (page 6)

Chapter 1 Review of Equations and Inequalities

Polynomials; Add/Subtract

Math From Scratch Lesson 29: Decimal Representation

Section 4.7 Scientific Notation

KNOWLEDGE OF NUMBER SENSE, CONCEPTS, AND OPERATIONS

The Basics COPYRIGHTED MATERIAL. chapter. Algebra is a very logical way to solve

And the radius of an electron is thought to be even smaller again, at about one onethousandth of the radius of a proton!

Sect Scientific Notation

Solving Equations. Lesson Fifteen. Aims. Context. The aim of this lesson is to enable you to: solve linear equations

Addition & Subtraction of Polynomials

CSE 20: Discrete Mathematics

Park Forest Math Team. Meet #3. Number Theory. Self-study Packet

Number System conversions

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Binary addition (1-bit) P Q Y = P + Q Comments Carry = Carry = Carry = Carry = 1 P Q

CHAPTER 1. REVIEW: NUMBERS

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

Prepared by Sa diyya Hendrickson. Package Summary

Correlations to the Common Core State Standards: Kindergarten

Part I, Number Systems. CS131 Mathematics for Computer Scientists II Note 1 INTEGERS

Section 1.1: Patterns in Division

Free Pre-Algebra Lesson 31! page 1

Mathematics I. Quarter 2 : ALGEBRAIC EXPRESSIONS AND FIRST-DEGREE EQUATIONS AND INEQUALITIES IN ONE VARIABLE

Number Theory: Representations of Integers

Digital Systems Overview. Unit 1 Numbering Systems. Why Digital Systems? Levels of Design Abstraction. Dissecting Decimal Numbers

Digital Logic (2) Boolean Algebra

Mathematics Tutorials. Arithmetic Tutorials Algebra I Tutorials Algebra II Tutorials Word Problems

ABE Math Review Package

LESSON ASSIGNMENT. After completing this lesson, you should be able to:

Radiological Control Technician Training Fundamental Academic Training Study Guide Phase I

Unit II Chapter 4:- Digital Logic Contents 4.1 Introduction... 4

LAMC Intermediate I & II October 12, Oleg Gleizer. Warm-up

ARITHMETIC AND BASIC ALGEBRA

SERIES

1 Computing System 2. 2 Data Representation Number Systems 22

1.1.1 Algebraic Operations

Arithmetic with Whole Numbers and Money Variables and Evaluation

Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5

Transcription:

Introduction to counting and positional notation. In the decimal number system, a typical number, N, looks like... d 3 d 2 d 1 d 0.d -1 d -2 d -3... [N1] where the ellipsis at each end indicates that there is no limit on the number of digits a number might have. Each d i is a decimal digit which can only take on the values 0 through 9. Consider just the integer portion of a decimal number having 4 digits: d 3 d 2 d 1 d 0. In a positional number system each digit has a weight, depending on which column (or position) it occupies in the number. Thus, d 0 is in the ones column, d 1 is in the tens column, d 2 is in the hundreds column, etc. Now, note that 1 = 10 0, 10 = 10 1, 100 = 10 2, 1000 = 10 3, and so on. We could say, therefore, that d 0 has a weight of 10 0, d 1 has a weight of 10 1, d 2 has a weight of 10 2, etc. When we consider what the actual value of d 3 d 2 d 1 d 0 is we mentally perform the following calculation: d 3 x 10 3 + d 2 x 10 2 + d 1 x 10 1 +d 0 x 10 0 [N2] So, for example, the number 538 is five hundred and thirty eight. Algebraically, [N2] can be rewritten as: 3 d i 10 i i=0 [N3] Similarly, the fractional part of the decimal number given in [N1],.d -1 d -2 d -3, is interpreted as d -1 x 10-1 + d -2 x 10-2 +d -3 x 10-3 since d -1 is in the tenths column, d -2 is in the hundredths column, etc. Similarly to [N3], the fractional part of the number can be expressed as -3 d i 10 i i=-1 [N4] We say that the base of the decimal number system is ten, represented by the symbol NTC 1/23/05 7

10. We can also use the term radix as a substitute for base. However, there is nothing magical about the number ten, and any other number can serve as the base, or radix, of a number system. The first thing to remember is that whatever the base (call it r for generality), there are only r digits in the number system: 0 through r-1. Consider, for example, a number system based on base 8. The only digits available in such a system are 0, 1, 2, 3, 4, 5, 6, and 7. When counting, when we run out of digits, we note this by putting a 1 in the next column and starting over at 0 in the first column. Just as in decimal. The numbers zero through sixteen in base 8 notation are 0 zero 10 eight 1 one 11 nine 2 two 12 ten 3 three 13 eleven 4 four 14 twelve 5 five 15 thirteen 6 six 16 fourteen 7 seven 17 fifteen [N5] 20 sixteen In the base 8 system, just as in the decimal system, each column has a weight, based on which column it is in. The rightmost column in a base 8 integer is the ones column, the next column is the eights column, the third column is the sixty-fours column. In general, the weight of each column is the number eight raised to the power of the column, starting with zero. This is identical to the decimal system. So, a three digit octal number, d 2 d 1 d 0, is interpreted, similarly to [N2] as d 2 x 8 2 + d 1 x 8 1 + d 0 x 8 0 [N6] which can be expressed similarly to [N3] as 2 d i 8 i i=0 [N7] Fractional parts of numbers in the base eight system follow the same scheme, so that the first fractional digit is the eighths column (8-1 ), followed by the sixty-fourths (8-2 ) column, and so on. NTC 1/23/05 8

These remarks are valid for any integer you care to choose as the base of a positional number system, so we can make the following generalizations: a. If r is the base (radix) of a number system, the only digits, d i, available in that number system are 0, 1,... r-1. b. The value of any number, N, in such a number system is given by +k d i r i i= -j [N8] where d -j is the least significant digit and d k is the most significant digit. It is often difficult, especially when talking about multiple number systems, to know which system a number is being represented in, For instance, how do I know that 1100 is a binary number (twelve) and not a trinary (or ternary) number (thirty-six), an octal number (Five hundred seventy six), or decimal (one thousand one hundred)? We will use a decimal subscript to indicate the base (radix): 1100 2 = 12 10 = 14 8 = C 16. Notes: Regardless of the number system, the rules of arithmetic do not change. As long as you remember the number of digits you have available in the number system of choice you should be able to do simple addition, subtraction and multiplication in any number system (division is harder, not because it is different, but because we are not used to thinking in the alternative number system.) Here are three examples in radix 6. 153 6 323 6 45 6 + 214 6-115 6 x 32 6 ------------ ------------- ----------- 411 6 104 6 134 223 ----------- 2404 6 Regardless of the number system, the radix itself is always represented by 10 r in that radix (that is, r = 10 r ). We need to break ourselves of the habit of thinking 10 = ten and instead think of it as one-zero, with the appropriate meaning in the number system at hand. Some examples: 8 10 = 10 8 5 10 = 10 5 16 10 = 10 16 2 10 = 10 2 Similarly, r 2 = 100 r, r 3 = 1000 r, etc. regardless of the value of r. NTC 1/23/05 9

As in the decimal system, r n is equal to 1 followed by n zeros. 2 4 10 = 10000 2 8 5 10 = 100000 8 16 2 10 = 100 16 Multiplying a number by r in any number system adds a zero to the end of the number, just as in base 10. More accurately, multiplying by r moves the radix point (decimal point in base 10, binary point in base 2, etc.) one place to the right. (And of course dividing by r moves the radix point one place to the left.) In general, 123 4 x 10 4 = 1230 4 1011 2 x 10 2 = 10110 2 d n-1..d 1 d 0 x r = d n-1...d 1 d 0 0 (or d n...d 1 d 0 where d 0 = 0) Binary and Hexadecimal Number systems The binary number system is one with a radix of 2. It has only two digits, 0 and 1. Binary numbers are important in computer science because of the nature of digital computers. Digital computers are built out of devices which generally have only two states, like a switch has only the states on and off. Electrical devices may have a positive or negative voltage, current may be flowing or not flowing, magnetic fields may flow in one of two directions and so on. Transistors are used a switches throughout a computer system and they either conduct current or they don t. These two states are the on and off of a switch. The two states of electronic devices are generally given conceptual values depending on what they are intended to represent, such as yes and no, or true and false. For conciseness as well as because there is useful mathematical meaning, we generally assign the symbols 0 and 1 to these two states. Here are the first sixteen binary numbers: 0 zero 1000 eight 1 one 1001 nine 10 two 1010 ten 11 three 1011 eleven 100 Four 1100 twelve 101 five 1101 thirteen 110 six 1110 fourteen 111 seven 1111 fifteen Hexadecimal numbers are numbers in a number system with radix of 16. Note that, NTC 1/23/05 10

since there is nothing magical about the number ten, there is no requirement that number system bases be less than ten. The problem with larger number bases, of course, is that we don t have symbols for digits greater than nine. Since we need sixteen digits for the hexadecimal number system, we use the letters A, B, C, D, E, and F to stand for the digits ten, eleven, twelve, thirteen, fourteen, and fifteen, respectively. Here are the first sixteen numbers expressed in the hexadecimal system: 0 zero 8 eight 1 one 9 nine 2 two A ten 3 three B eleven 4 four C twelve 5 five D thirteen 6 six E fourteen 7 seven F fifteen [N9] 10 sixteen NTC 1/23/05 11

NUMBER DECIMAL BINARY HEXADECIMAL OCTAL Zero 0 0000 0 0 One 1 0001 1 1 Twp 2 0010 2 2 Three 3 0011 3 3 Four 4 0100 4 4 Five 5 0101 5 5 Six 6 0110 6 6 Seven 7 0111 7 7 Eight 8 1000 8 10 Nine 9 1001 9 11 Ten 10 1010 A 12 Eleven 11 1011 B 13 Twelve 12 1100 C 14 Thirteen 13 1101 D 15 Fourteen 14 1110 E 16 Fifteen 15 1111 F 17 Table TN1. The table TN1 shows the numbers zero thru fifteen in all the number systems most commonly used in computer science. Radix Conversion It is often necessary (in Computer Science, at least) to convert numbers from one number system to another. For instance, the fact that the value of the binary number 11100101 2 is 229 10 is not immediately obvious. We present here a general procedure for converting a number in one radix, r o, (o for old) to a number in radix r n (n for new). Converting Integers NTC 1/23/05 12

Assume we have a number in radix r o and we want to convert to a new radix r n. Clearly each digit in the number in the new base must be less than r n (0 thru r n -1), and this will be true if we generate the digits for the new number by dividing the old number by the new radix (written in the old base) and retaining the remainder. Recall that this is the MOD operation. We also determine Q, using the DIV operator. We then iteratively use the DIV and MOD operators on the new Q generated each time. Each remainder produced by MOD is a subsequent digit of the number in the new radix; each Q produced by DIV is used for the next iteration s MOD. It is important to note that the digits are produced least significant first. Here is the algorithm in more compact form: Q 0 = N div r n d 0 = N mod r n Q 1 = Q 0 div r n d 1 = Q 0 mod r n Q i = Q i-1 div r n d i = Q i-1 mod r n Continue until Q i = 0. Note that, when the new radix is smaller than the old radix, at the conclusion of the above operations all the d i will be in the desired form. However, if the new radix is larger than the old radix we need to express the new radix in the form of the old number system and do all arithmetic in the old number system. The remainders will also be represented in the old number system and then have to be converted to the new number system s digits. Examples: 1. Convert 43 10 to Base 3 N =43 10 r n = 3 10 Q 0 = 43 div 3 = 14 d 0 = 1 Q 1 = 14 div 3 = 4 d 1 = 2 Q 2 = 4 div 3 = 1 d 2 = 1 Q 3 = 1 div 3 = 0 d 3 = 1 Since Q 4 = 0 we are done. The result is 43 10 = 1121 3 Note that digits are generated starting at the radix point. NTC 1/23/05 13

2. Convert 1121 to Base 10. N = 1121 3 r n = 10 First we must convert the new base to the base 3 number system (using the techniques exemplified in example 1). Then r n = 10 10 = 101 3 Q 0 = 1121 3 div 101 3 = 11 3 d 0 = 11 3 Q 1 = 11 3 div 101 3 = 0 d 1 = 11 3 Since Q 1 is 0, the algorithm terminates. But since the d i are in base 3 we need to convert them to decimal digits. We will see a shortcut for doing this shortly; for now accept that so that d 0 = 10 3 = 3 10 and d 1 = 11 3 = 4 10 1121 3 = 43 10 as shown in example 1. 3. Convert 4301 5 to base 3 N = 4301 5 rn = 3 Since the new radix is smaller than the old one, no additional conversions will be necessary. However, all divisions must be done in base 5, which you may find unnatural. Q 0 = 4301 5 div 3 = 1232 5 d 0 = 0 Q 1 = 1232 5 div 3 = 224 5 d 1 = 0 Q 2 = 224 5 div 3 = 41 5 d 2 = 1 Q 3 = 41 5 div 3 = 12 5 d 3 = 0 Q 4 = 12 5 div 3 = 2 5 d 4 = 1 Q 5 = 2 5 div 3 = 0 5 d 5 = 2 NTC 1/23/05 14

Thus, 4301 5 = 210100 3 4. Convert 84710 to base 16 N = 847 10 r n = 16 10 Q 0 = 847 10 div 16 = 52 10 d 0 = 15 10 Q 1 = 847 10 div 16 = 3 10 d 1 = 4 10 Q 2 = 847 10 div 16 = 0 d 2 = 3 10 We need to convert the decimal remainders to hexadecimal digits (see [N9]). When this is done the result is so d 0 = F,d 1 = 4, d 2 = 3 847 10 = 34F 16 We will not be too concerned in this text with conversions between arbitrary number systems, but will confine ourselves largely to conversions among the binary, decimal, hexadecimal and, possibly, octal number systems as these are the ones most commonly found in computer systems. since we are all very familiar with decimal numbers there are some shortcuts we can use. Consider the special case when the new radix is 10. Converting a number in an arbitrary radix number into the base 10 number system is easily done by evaluating the expression d i r i ([N8]). Examples: 5. Convert 1121 3 to base 10 (this is example 2 above.) 1121 3 = 1 x 3 3 + 1 x 3 2 + 2 x 3 1 + 1 x 3 0 = 1 x 27 + 1 x 9 + 2 x 3 + 1 x 1 = 27 + 9 + 6 + 1 = 43 10 6. Verify the results of example 3 above by converting both numbers to decimal using this shortcut method. NTC 1/23/05 15

4301 5 = 4 x 5 3 + 3 x 5 2 + 0 x 5 1 + 1 x 5 0 = 4 x 125 + 3 x 25 + 0 x 5 + 1 x 1 = 500 + 75 + 0 + 1 = 576 10 210100 3 = 2 x 3 5 + 1 x 3 4 + 0 x 3 3 + 1 x 3 2 + 0 x 3 1 + 0 x 3 0 = 2 x 243 + 1 x 81 + 0 x 27 + 1 x 9 + 0 x 3 + 0 x 1 = 486 + 81 +0 + 9 + 0 + 0 = 576 10 In general, converting between two arbitrary number systems is done most easily by converting the number in the old system to base 10 and then converting the base 10 version of the number to the new number system. 7. Verify the results of example 4 by converting the result 34F 16 to base 10 using this method. 34F 16 = 3 x 16 2 + 4 x 16 1 + F x 16 0 = 3 x 16 2 + 4 x 16 1 + 15 x 16 0 (converted the hex digit F to decimal 15) = 3 x 256+ 4 x 16 + 15 x 1 = 768 + 64 + 15 = 847 10 This is the method we used to convert the digits in example 2 above to decimal. Another special case exists when both old and new radix are powers of the same base number. For example base 16 and base 8 are both powers of base 2. Do it in two steps: 1) convert the number to the common base, then 2) convert to the new radix. Why is this simple? Because converting from, say, 16 to base 2 requires no computation, nor vice versa. Example: 8. Convert base 16 to base 8: D5A 16 = 6532 8 1. Convert to base 2: 1101 0101 1010 2. Regroup bits (starting from right to left) into groups containing 3 bits: 110 101 011 010 3. Convert each group of bits to base 8: 6532 8 It is common to use hexadecimal numbers as shorthand for binary numbers in computer science. Memory addresses, for instance, are 32 bits in size in modern PCs NTC 1/23/05 16

(and 64 bits in most workstations). It is much more convenient to work with 8 hex digits than it is to work with 32 binary digits. Example: 9. represent the 32 bit binary address 10010101010111111000110011010001 in hexadecimal. Four bit groups = 1001 0101 0101 1111 1000 1100 1101 0001 2 Using [TN1] = 955F8CB1 16 Practice Problems - Integer Number System Conversions 1. Convert the decimal integer 427 10 into the following number systems: a. Binary (base 2) c. Octal (base 8) b. Ternary (base 3) d. Hexadecimal (base 16) 2. Convert the following numbers to decimal integers. a. 100111101 2 c. 162 7 b. 162 8 d. A4E 16 3. Convert the following decimal integers to binary: a. 2 c. 27 e. 128 g. 31 b. 245 d. 127 f. 17 h. 257 4. Which of the following are not valid numbers in the radix indicated? a. 123 4 d. 123 5 g. 123 3 b. DEF 16 e. 827 8 h. 100100 3 c. 11111 2 f. 21210 3 i. 501 4 Converting Fractions Converting Fractions uses iterative multiplication instead of modulo division. Multiply the fraction, N, by the new radix, r n (in the old radix representation), to get a product P; if the result is greater than one, the integer part is the next fractional digit. If it is less NTC 1/23/05 17

then one, zero is the next fractional digit. The fractional part, after multiplication, is used for the next multiply. The digits produced are the most significant to the least significant (i. e. starting at the radix point). Example: 10. Convert decimal.834 to base 3: P -1 =.834 x 3 = 2.502 d -1 = 2 P -2 =.502 x 3 = 1.506 d -2 = 1 P -3 =.506 x 3 = 1.518 d -3 = 1 and so on. The fraction.834 10 =.211.. 3 Notice that in this example there was no clear point at which we knew that we were finished. There are three situations which may occur when converting fractions: 2. The remaining fraction is zero. You are done. Convert.75 10 to binary..75 x 2 = 1.50 d -1 = 1.50 x 2 = 1.00 d -2 = 1 Since the fraction is now zero, we can stop..75 10 =.11 2 3. The remaining fraction repeats a previously obtained fraction. You can stop, realizing that the answer is a repeating fraction in the new base. Convert.3 to binary..3 x 2 = 0.6 d -1 = 0.6 x 2 = 1.2 d -2 = 1.2 x 2 = 0.4 d -3 = 0.4 x 2 = 0.8 d -4 = 0.8 x 2 = 1.6 d -5 = 1.6 x 2 = 1.2 d -6 = 1 Since the fraction (.6) has repeated we can stop. After the initial 0, the answer is a repeating fraction with 1001 repeating forever: 0100110011001... NTC 1/23/05 18

4. Neither of the above situations occurs, and you get tired. You may have a non-repeating, non-ending fraction (like pi). It is also possible that you have a repeating fraction with a very large number of positions repeating. Note that, as a practical matter, the number of decimal digits you generate is determined by the requirements of the problem you are solving. For any given problem, it only makes sense to retain the number of significant digits required by the application. Again, when the new radix is 10, it is easiest to use [N8]: d i r i. Example: 11..11 2 = 1 x 2-1 + 1 x 2-2 = 1x ½ + 1 x 1/4 = 3/4 =.75 10 As with integer numbers, when both radixes are powers of a common base it may be easier to convert first to the common base and then to the new base. For example base 2 and base 16 because 16 = 2 4. In this case, convert groups of four binary digits to hex digits, or vice versa. Converting between base 8 and 16, just convert first to binary, then to the desired base. Example: Convert.DA 16 to? 8.DA 16 =.11011010 2 =.110 110 10 =.662 8 Note that grouping is always done starting at the radix point. NTC 1/23/05 19

Practice Problems - Fraction Number System Conversion 1. Convert the following fractions to binary: a..875 b..2 c..71 2. Convert the following fractions from the base indicated to decimal: a..01101 2 c..00001 2 e..163 7 b..a26 16 d..121 3 f..444 5 NTC 1/23/05 20