number systems

35
MA 102 METHODS OF MATHEMATICS Discrete Mathematics Course Outline Number Systems Number bases; the decimal, binary, octal and hexadecimal systems; calculating in the binary, octal and hexadecimal systems, converting between bases, representing fractions, negative numbers. Sets Binary operations,Venn diagram, laws, applications. Functions and sequences Ordered pairs, tree diagrams, relations and types, functions, sequences.

Upload: hasithr

Post on 22-Oct-2015

39 views

Category:

Documents


6 download

DESCRIPTION

Methods of mathematics - simple guide to number systems

TRANSCRIPT

Page 1: Number Systems

MA 102 METHODS OF MATHEMATICS

Discrete Mathematics Course Outline

• Number Systems

Number bases; the decimal, binary, octal and hexadecimal systems; calculating in the binary, octal and hexadecimal systems, converting between bases, representing fractions, negative numbers.

• Sets

Binary operations,Venn diagram, laws, applications.

• Functions and sequences

Ordered pairs, tree diagrams, relations and types, functions, sequences.

Page 2: Number Systems

2

1. Number Systems Introduction The history of mathematics began thousands of years ago with numbers and counting.Today numbers are more important in our lives than ever before with information in every field, from pin numbers and bar codes to music and television transmissions recorded digitally. In this section, we consider various ways in which numbers can be represented. Number Bases The Decimal Number System(Numbers in Base 10) Suppose that 23.... aaan 01aa represents a positive decimal number, where the symbols 0123 ,,,,..., aaaaan each represents one of the digits 0,1,2,…..,9 (not necessarily different from one another). The following two methods give the actual value V of the number. Method 1 We can think of each digit as appearing in a labeled box , where each box has a place value, according to its positions illustrated below.

Page 3: Number Systems

3

The place value of each digit determines how much it contributes to the value of the number.

….

n10

…..

310

210

110

010

….

na

…..

3a

2a

1a

0a

The name decimal reflects the fact that every place value in our system is a power of 10. Note: The decimal system has base 10. The number 0123..... aaaaan in expanded notation can be written as, V= )1()10()10()10(.............)10( 0

11

22

33 aaaaa n

n +++++ . Method 2 Double Bubble Method Step 1 Take V=a n Step 2 Multiply V by 10, Then V 10*V→ Step 3 Add next digit, nextdigitVV +→ Step 4 If not end go to step 2. Example:

Page 4: Number Systems

4

Suppose that 0123 aaaa represents a decimal number. Then we can write 0123 aaaa in expanded notation in the base 10, as

01

12

23

3 )10()10()10( aaaaV +++= In Double Hubble method

0123 10*))10*)10*(((( aaaaV +++= The Binary System Most modern computer systems operate using binary logic. A digital computer is just a collection of on/off switches, with an intricate set of connections between them. Thus the two positions of a switch are represented by digits 0 and 1. Therefore, the whole purpose of using binary notation is for constructing on/off circuits that can represent bit values in terms of two voltage values, either high or low. Binary numbers Definition: The number system with base 2 ,having just two digits 0and 1,is called the binary number system. Each binary digit is called a bit(short for binary digit.). A string of bits like 10001011 is called a binary string. To represent numbers in binary system the box system in binary as shown below is used giving the place value of each bit.

Page 5: Number Systems

5

Conversion of Decimal to Binary To convert 15 to binary keep on dividing by 2 as follows. 2 15 2 7 - 1 2 3 - 1

1 -1 15 = 2)1111( The following table shows the binary equivalent of decimal numbers from 1 to 16. base 10 base 2 base 10 base 2 1 (1) 2 9 (1001) 2 2 (10) 2 10 (1010) 2 3 (11) 2 11 (1011) 2 4 (100) 2 12 (1100) 2 5 (101) 2 13 (1101) 2 6 (110) 2 14 (1110) 2 7 (111) 2 15 (1111) 2

… 52 42 32 22 12 1

Page 6: Number Systems

6

8 (1000) 2 16 (10000) 2

Conversion of Binary to Decimal

Just like the decimal system, each digit is multiplied by its weighted position, and add each of the weighted values together. Example Convert the binary integer 2)1001011( to the decimal system.

62

52

42

32

22

12

1

1 0 0 1 0 1 1

When finding the decimal equivalent of a binary number, it is easy to work from right to left.

)2(1)2(0)2(0)2(1)2(0)2(1)1(1)1001011( 6543212 ++++++=

631 2221 +++= 75= In Double Bubble method,

12*)12*)02*)12*)02*)02*1((((()1001011( 2 ++++++= Consider the binary number 201234 )( aaaaa where each of the symbols ia represents a bit (0 or 1). When converted to Decimal it is equal to ,

Page 7: Number Systems

7

)1()2()2()2()2( 01

12

23

34

4 aaaaa ++++ in expanded notation. Ex: Use Double Bubble Method also. Exercise: Convert the following binary numbers to decimal. (i) 110101 (ii) 11100011 (iii)101110001 Calculating in the Binary System Binary Addition In the decimal system when we add a column of digits that sum to a number greater than 9,units in the column that we are working in are recorded and carry the number of 10’s into the next column to the left. We proceed in a very similar way in binary. The rules for addition (1) 222 )0()0()0( =+ (2) 22222 )0()1()1()1()0( +==+ To obtain rules for carrying, suppose the column to be added is as follows. (3) 222 )10()1()1( =+ (since 1+1= 2)

Page 8: Number Systems

8

Record the zero in the current column and carry 1 to the next column to the left. (4) 2222 )11()1()1()1( =++ (since 1+1+1=3) Record 1 in the current column and carry 1 to the next column to the left. (5) 22222 )100()1()1()1()1( =+++ Record 0 in the current column and carry 1 to the column two places to the left. Example: Find the sum of the binary numbers .)11()1111()1011( 222 ++ In the format below ,the numbers we carry at each step are recorded above the horizontal line. Step 1: Adding the right hand 1 column we obtain 2)11( 10 1 1 and so we record 1 and 11 1 1 carry 1 into the next 1 1 column (that is 12 column). 1 Step 2: Adding the 12 column, we 1 1 obtain 2)100( and so we record 1011 0 and carry 1 into the 1111 column two places left (that 11 is the 32 column)

Page 9: Number Systems

9

01 Step 3: Adding 22 column we obtain 2)1( ,so this time 1 1 1 nothing to carry.Adding 1011 the 32 column we obtain 1111 2)11( so we record 1 and 11 carry 1 into 42 column. 1 1101 Adding 42 column we obtain 2)1( and process terminates. Thus we obtain 2222 )11101()11()1111()1011( =++ . In decimal numbers , this addition is 11+15+3=29. Exercise: Perform following binary additions (i) 11111 + 111 (ii) 100110 + 101010 (iii) 11001 + 11 Check your answers by converting to decimal. Binary Subtraction To evaluate 123-36 we must borrow a 10. We shall now carry out the same process in binary, where we have to borrow a 2 when we have to perform the subtraction 22 )1()0( − in any column.

Page 10: Number Systems

10

To obtain the rules for borrowing, suppose the column to be subtracted is as follows. 1. 222 )0()0()0( =− 2. 222 )1()0()1( =−

3. 222 )0()1()1( =− 4. 222 )1()1()0( =− after borrowing 1 from left of bigger number. i.e. It becomes 22 )1()10( − . Example: Subtract .)101011()1101000( 22 − Step 1: 11001110 We have to borrow to 110100 0 perform the subtraction 10101 1 in the units column.The first column with a non zero entry is the 32 column. We borrow 2)1000( from this column. The revised row is recorded above the horizontal line. ( )222)11(222*22222*22 2222223 ++=++=+=+== Step 2: 10110 110 01110 10 101 1

Page 11: Number Systems

11

10 1 Step 3: 010 1 01101110 10 101 1 1 110 1 Thus 222 )111101()101011()11010000( =− . In decimal 104 – 43 = 61. Exercise: Perform following binary subtractions. (i) 1111-111 (ii) 11001-101 (iii) 100001-11 Check your answers by converting to decimal. Binary Multiplication The process of binary multiplication is very similar to long multiplication in the decimal system. Example: Multiply 22 )101()1011( x . 1011 101 1011 10110 110111

Page 12: Number Systems

12

Check whether this is correct by finding the decimal equivalent. Exercise: Perform the following binary multiplications. (i) 1111 x 1101 (ii) 1011 x 111 (iii) 11011 x 11101 Check your answers by converting to decimal. Consider 743 x 10. Writing 743 in expanded notation, 743 = ).1(3)10(4)10(7 12 ++ 743 x 10 = )1(0)10(3)10(4)10(7 123 +++ Thus the place value of each digit has been multiplied by 10 and the entry in the units column is now 0. A similar thing happens when we multiply a binary number by the base number 2= 2)10(

A familiar feature in decimal is that when we multiply any whole number by 10, we move all the digits one place to the left and enter a zero in the units column.

Page 13: Number Systems

13

Now consider 2)( 21234 xaaaaa o 21234 )( oaaaaa = )1()2()2()2()2( 0

11

22

33

44 aaaaa ++++

2)( 1234 xaaaaa o = )1(0)2()2()2()2()2( 10

21

32

43

54 +++++ aaaaa

RULE : To multiply by 2)10( in binary , we move each bit one place to the left and enter 0 in the 02 column. This rule can be extended to multiply by any power of 2. For example multiply by 4 is multiply by 2 and again multiply the result by 2. So we move each bit two places to the left and enter zeros in both the 12 Column and 02 columns. Thus the rule for multiplying by 4 = 2)100( in binary is exactly the same as the rule for multiplying by 100 in decimal. Exercise: Perform following binary multiplications.

Thus the place value of each bit has been multiplied by 2 and so the bits all move one place to the left and the entry in the units column is 0.

Page 14: Number Systems

14

(i) 1011 x 10 (ii) 11011 x 100 Check your answers by converting to decimal. Binary division The process of long division in the binary system is very similar to long division in the decimal system. Key operations are, 0/1=0 and 1/1=1. Example: Calculate 22 )11/()101001( 1101 11 101001 11 100 11 222 )1101()11/()101001( = with

101 remainder 2)10( . 11 In decimal 133/41 = with 10 remainder 2. Exercise Perform following binary divisions. (i) 101100 / 101 (ii) 1001110 / 111 (iii) 100110 / 110 Check your answers by converting to decimal. Note:

Page 15: Number Systems

15

Dividing by 2 is just the reverse of the process of multiplying by 2 . Therefore the following rule applies. Rule To divide by 2)10( in binary we move each bit one place to the right and the entry in the unit column becomes the remainder. Example

222 )11011()10/()110111( = , remainder 2)1( . The divisor is 2)10( and quotient is 2)11011( . Exercise Perform the following binary divisions (i) 101100 / 100 (ii) 1001110 / 10 Check your answers by converting to decimal. Conversion of Decimal to binary Method 2 For this method , divide the decimal number by 2, if the remainder is 0, on the side write down a 0. If the remainder is 1,write down a 1. This process is continued by dividing the quotient by 2

Page 16: Number Systems

16

and dropping the previous remainder until the quotient is 0. Step 1 - Divide decimal number by 2 , giving quotient 1Q , remainder 1R . Step 2 - Divide last quotient LQ by giving Q and remainder R . Step 3 - If last ,0≠Q go to 2 Step 4 - Binary number, b=….. 123 RRR Example: Convert the decimal number 2671 to binary.

Division Quotient Remainder Binary number

2671/2 1335 1 1 1335/2 667 1 11 667/2 333 1 111 333/2 166 1 1111 166/2 83 0 01111 83/2 41 1 101111 41/2 20 1 1101111 20/2 10 1 01101111 10/2 5 0 001101111 5/2 2 1 1001101111 2/2 1 0 01001101111

Page 17: Number Systems

17

1/2 0 1 101001101111 Exercise: Convert the following decimal numbers to binary (i) 24 (ii) 282 (iii) 5731 Octal number system The octal system is based on the binary system with a 3-bit boundary. The octal number system uses base 8 and include only the digits through 0 and 7. Arithmatic in Octal Octal arithmetic is very similar to decimal arithmetic. Here we carry or borrow 8’s instead of 10’s. Octal or decimal Conversion To convert from Octal to Decimal, multiply the value in each position by its octal weight and add each value. Example: Convert the octal number 8)547( to decimal.

383)1(7)8(4)8(5)547( 12 =++=

28 18 1

5 4 7

Page 18: Number Systems

18

Binary to Octal conversion It is easy to convert from an integer binary number to Octal. This is accomplished by (i)Break the binary number into 3-bit sections from the bit in the units column and working to the left. (ii) Convert the 3-bit binary number to its octal equivalent. In the following table you will see that each binary number is expressed as a 3-bit string, by adding zero where necessary at the front of each binary number to make up the total number of bits to three.

Octal 8)0( 8)1( 8)2( 8)3( 8)4( 8)5( 6(

3-bit binary

2)000( 2)001( 2)010( 2)011( 2)100( 2)101( 1(

Example: Express the binary number 2)1100101010111110( as an Octal number. 1010111110110010=001 010 111 110 110 010

82 )127662()1100101010111110( = Exercise: Express the following binary numbers as octal numbers.

Page 19: Number Systems

19

(i) 2)111001100( (ii) 2)01100101011(

Octal to binary Conversion It is also easy to convert from an integer octal number to binary using the following.

1. Convert the decimal number to its 3-bit binary equivalent.

2. Combine the 3-bit sections removing the spaces. Example Express the octal value 8)127662( as binary. 127662= 001 010 111 110 110 010 28 )101100100010101111()127662( = Exercise Express following octal values in binary. (i) 8)264( (ii) 8)1456( Conversion of Decimal to Octal As in the binary conversion decimal number is repeatedly divided by 8 and remainders were recorded.

Page 20: Number Systems

20

Example Express the decimal number44978 as an octal Number. Division Quotient Remainder Octal

Number

44978/8 5622 2 2

5622/8 702 6 62

702/8 87 6 662

87/8 10 7 7662

10/8 1 2 27662

1/8 0 1 127662

Exercise Express following decimal numbers as octal numbers. (i) 684 (ii) 9251

Page 21: Number Systems

21

The Hexadecimal Number System To represent large numbers the binary system requires more digits. The hexadecimal system based on 16 solves this problem and it has the following advantages.

1. It enables most numbers to be recorded using Substantially fewer digits than are necessary in base 2. 2. There is a very easy method of converting between hexadecimal and binary. The hexadecimal system is based on the binary system using a 4-bit boundary. In order to express a number in the hexadecimal system we need 16 digits. The digits 0,1,…..,9 followed by the letters A,B,C,D,E and F are used.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15Hex- decimal

0 1 2 3 4 5 6 7 8 9 A B C D E F

The hexadecimal digits are known as hexits and hexadecimal system is often called hex. Hex to Decimal Conversion

Page 22: Number Systems

22

To convert from Hex to Decimal multiply the value in each position by its hex weight and add each value. Example Convert the hex number 16)75( AE to decimal.

316 216 116 15 A E 7

)1(7)16(14)16(10)16(5)75( 123

16 +++=AE .23711= Or

23711716*)1416*)1016*5((( =+++ Arithmatic in Hex Hexadecimal arithmetic is very similar to decimal arithmetic, except that we have 16 hexits and carry or borrow 16’s instead of 10’s. Example

16)79( D 16)4( BA+ Hexits we carry are entered in the row above the horizontal line. 11 9D7 161616 )91()4()79( EBAD =+

Page 23: Number Systems

23

4BA In decimal 2519+1210=3729 E91 Example

1616 )9()04( CDF − EF14 F04 161616 )22()9()04( BCDF =− CD9 In decimal, 22B 3844-3289=555 Decimal Fractions To represent a rational number in base 10 in expanded notation, the place values as illustrated below are used.

The decimal expansion of a fraction either terminates after a finite number of places or has a recurring block of figures.

Page 24: Number Systems

24

Example 17/20=0.85 and 3/8 = 0.375 5/12=0.416666…….. digit 6 has recurred 7/11 = 0.636363…… recurring block of figures. Suppose we are given a terminating or repeating decimal . The following method is used to express it as a fraction m/n , where m and n are integers. Example Express the repeating decimals 0.272727…. as a fraction of its lowest terms. Step 1 Determine the number of digits in the repeating block. In this case the repeating block is 27 and the number of digits is 2. Step2 Write .............272727.0=x and multiply x by

210 where the power of 10 is the length of the repeating block. This gives 100 x = 27.272727……. Step 3

Page 25: Number Systems

25

Subtract x from 100x 100x = 27.272727…… - x = 0.272727…. 99x = 27.000000…. Step 4 Solve the equation to find x. 99x=27 x = 27/99 = 3/11. Example Express the repeating decimals 0.15333….. as a fraction of its lowest terms. In this case, repeating block is single digit 3 and number of digits is 1. Let x = 0.153333….. 10x = 1.53333…

- x = 0.15333…. 9x = 1.38 x = 1.38 / 9 = 138/900 = 23/150.

Result The rational numbers are those numbers that can be represented as a terminating or recurring decimal. Fractions in base other than 10

Page 26: Number Systems

26

The place values in the full binary system are as follows. …. 42 32 22 12 1 12− 22− 32− 42− ….. Example Express the binary number 2)1101.0( in base 10.

1

2(1−

8125.016/14/12/1)2(1)2(0)2(1) 432 =++=+++ −−− An alternative method is first express 2)1101.0( as a binary fraction , and then convert both the numerator and the denominator to base 10. 8125.0

1613

100001101)1101.0(

22 ==

=

Example Express the binary number 2)11.101( in 10.

75.52222)2(1)2(1)1(1)2(0)2(1 21022112 =+++=++++ −−−− Alternatively, 4/35)100/11()101()11.101( 222 +=+= = 5.75 The part with digits to the left of the point is called the integral part of the number and the part with digits to the right of the point is called fractional part of the number. Thus the integral part of 2)11.101( is 2)101(

Page 27: Number Systems

27

And the fractional part is 2)11.0( Octal system The place values in the full octal system are as follows: …. 48 38 28 18 1 18− 28− 38− 48− …. Example Express the octal number 8)4.13( in base 10.

5.112/111)8(4)1(3)8(1 11 =+=++ − Hexadecimal system The place values in the full hexadecimal system are as in the octal system where 8 is replaced by 16. Example Express the number 16)3.7( BE in base 10. 256/1116/3231)16(11)16(3)1(7)16(14 211 ++=+++ −− Note To convert the fractional part of a binary number into the hexadecimal system first split the binary string into groups of four bits starting from the decimal point and working to the right. If the last

Page 28: Number Systems

28

block to the right contains less than four bits , add zeros as necessary and use the binary hex conversion table. Negative number representation Following methods are available to store negative numbers. All numbers are assumed to be stored in binary form. It is important to work with the word length of the machine. Word length is the number of bits required to represent a number. For example if 16 bits are used to represent an integer in a particular computer then we say that the machine has word length 16. Signed Bit Magnitude Representation Here, The first binary digit(left most bit) represents the sign. 0 for positive and 1 for negative numbers. Example Assume 4 bit computer word and represent decimal integers +7, -7 in binary.

102 7)111( = (positive) Extra bit representing sign, ( 0-positive,1- negative)

Page 29: Number Systems

29

102 70111 = ( positive) Extra bit representing sign, 102 71111 −= (negative) Exercise Assume 8 bit computer word and represent the following decimal integers in binary. (a) –48 (b) 48 (c) –27 One’s complement and Two’s complement Representations 1. Represent the magnitude of the binary in the given word length. (You may add zeros in front to fill blanks) 2. Complement each digit by flipping 1 to 0 and 0 to 1. This is called one’s complement of the given number. 3. Add 1 to one’s complement representation.

This is called two’s complement representation. With this strategy ,we assign the leftmost bit to serve a special purpose ,just as we did with the sign magnitude approach, defining our number limits as before. However , this time the leftmost bit is more than just a sign bit, rather it possesses a negative place-weight value.

Page 30: Number Systems

30

Example

Represent the value of the negative five using two’s complement.

21011 - two’s complement of negative 5 10101010102 5)11()21()40()81(1011 −=+++−= xxxx With the right 3 bits being able to represent a magnitude from zero through seven and the leftmost bit representing either zero or negative eight , we can represent any integer from negative seven to positive seven. Since, 1010102 7181001 −=+−= 1010102 7700111 =+=

Representing positive numbers in this scheme (with the fourth bit designated as the negative weight) is no different from that of ordinary binary notation. zero 0000 positive one 0001 negative one 1111 positive two 0010 negative two 1110 positive three 0011 negative three 1101 positive four 0100 negative four 1100 positive five 0101 negative five 1011 positive six 0110 negative six 1010 positive seven 0111 negative seven 1001 negative eight 1000

Page 31: Number Systems

31

Exercise: Represent in two’s complement format as 8 bit word length. (a) –47 (b) -44 Binary subtraction by two’s complement To calculate a-b, both in binary, 1. Represent the magnitude of the binary in the given word length. 2. Write 2’s complement of b as b′ 3. Find ba ′+

BCD(Binary Coded Decimal) Number System If we view single digit values for hex, the numbers 0-F , they represent the values 0-15 in decimal. This system is used for some purposes where each digit of a decimal number is converted to binary form. For this , since digits 0 to 9 are to be converted to binary, 4 binary bits are required to represent each digit. To represent a decimal number beyond 9 two or more decimal digits are needed that is BCD representation requires 2 or more 4-bit groups.

Page 32: Number Systems

32

BCD is just a code in binary, as opposed to a straight binary number ,which represents the actual value. The table below shows the binary and the BCD equivalents of decimals 0 through 15. Decimal Binary BCD 0 0000 0000 1 0001 0001 2 0010 0010 3 0011 0011 . . . . . . 10 1010 0001 0000 11 1011 0001 0001 12 1100 0001 0010 13 1101 0001 0011 14 1110 0001 0100 15 1111 0001 0101 Decimal to BCD conversion Each decimal digit is independently represented by its corresponding binary. 3 7 2 9 0011 0111 0010 1001

Page 33: Number Systems

33

BCD to Decimal conversion Starting from right , partition the binary pattern into groups of 4 bits each. Each group is then converted to its corresponding decimal number. Example Convert BCD)0100011001001101( to decimal. 1001 0001 0101 0001 9 3 5 1 Equivalent decimal number is 10)9351( . Exercise: (i) Convert the following numbers to BCD.

(a) 10)362( (b) 10)28.47( (c) 16)2.7( CAF

(ii) Convert the following BCD binary numbers to decimal.

(a) 100000100 (b) 11101011001.10011

Exercises 1. Write the decimal numbers 4037 and 40371 in expanded form as multiples of 10. 2. Express the following binary numbers as

Page 34: Number Systems

34

decimal numbers. (a) 2)11011( (b) 2)1100110( (c) 2)111111111( 3. Perform the binary additions.

(a) 2)10111( (b) 222 )1111()1011()1101( ++

4. Perform the binary subtractions.

(a) )111()1001( 2 − (b) 22 )10111()110000( −

5. Perform the binary multiplications.

(a) 22 )111()1101( x (b) 22 )1101()1101( x

6. Perform the binary division. 22 )101/()111011(

7. (a) Write the octal number 8)227( in binary. (b) Write the binary number 2)01011101110( in octal system. (c ) Write the hex number 16)4(EC in binary. (d) Write the binary number 2)1111011010( in hex.

8. Perform following calculations.

(a) 8)123( 8)107(+ and 8)123( 8)107(−

(b) 88 )4.10()72.234( + and 88 )4.10()72.234( −

Page 35: Number Systems

35

9. Perform following calculations.

(a) 816 )7.77()7.( +BC (b) 816 )2.7()7.( −BC

10.Represent the following numbers in signed bit magnitude format and in two’s complement format as 16 bit word length. (a) –47 (b) -44

11.Perform the following subtractions using two’s complement method. (a) 22 )111()1001( − (b) 22 )10111()110000( −