Vous êtes sur la page 1sur 13

CHAPTER 1 : NUMBER BASES

Chapter Objectives

At the completion of this chapter, you should be able to:

identify the different types of numbers;

convert between denary and other base;

convert between binary, octal and hexadecimal;

understand the column system and number bases;

understand modular arithmetic;

hexadecimal, octal addition.

understand the column system and number bases; understand modular arithmetic; hexadecimal, octal addition. 1 - 1

1 - 1

CHAPTER 1 : NUMBER BASES

CMA101

1.1 Introduction

In this chapter, we start to explore various sets of numbers which are used to represent data in real life problems. Namely, natural numbers, integers, rational, irrational, real and complex numbers. Numbers are used to represent quantities, measurement, and others in our surroundings. They are essential representations of data that will be processed by computer systems to produce useful information. The computer system, being a digital electronic device, has to handle data in binary numbers.

In binary numbers, each binary digit has only two states rather than ten states in decimal numbers. Therefore, binary, octal and hexadecimal number systems are dealt with in subsequent parts of the chapter.

1.1.1 Number Sets

N

Natural Positive integers Example: 3, 71

Z

Q

F

R

C

Integers Whole numbers Example: 3, -71

Rational Real numbers which can be expressed as the ratio of 2 integer Example: 1/2, 0.57, -3

Irrational Real numbers which are not rational Example:

2 , π

Real Can be represented by points a the straight line Example: - 2.31, 5 , 6

Complex No real number that can satisfy the equation X 2 = -

1Example:

−1 , − 5 , − 88
−1
,
− 5 ,
− 88

1.2 Level of Precisions

Some translator software have two levels of precisions in storing real numbers. Namely single-precision and double precision.

1 - 2

software have two levels of precisions in storing real numbers. Namely single-precision and double precision. 1

CMA101

CHAPTER 1 : NUMBER BASES

1.2.1 Single Precision

The real number is calculated to 8 and displayed to 7 significant figures.

Example:

π

=

3.1415926

calculated

 

=

3.141593

displayed

1.2.2 Double Precision

The computer will need longer processing time to produce double precision numbers. The real number is calculated to 16 and displayed on the screen to 15 significant figures.

Example:

π

=

3.141592653589793

calculated

 

=

3.14159265358979

displayed

1.3 Number Base

A fundamental counting group consists of a number of various symbols.

Counting Groups

Symbols of the Group

No. of Symbols

Binary 0, 1

 

2

Octal

0, 1, 2, 3, 4, 5, 6, 7

8

Hexadecimal

0, 1, 2, 3,

9, A, B, C, D, E, F

16

Denary

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

10

1.4 Column System

Enable us to represent any conceivable number by combining numerals and zeros.

For example, 423524 is derived from this column system:

Column No

6

5

4

3

2

1

Value

100,000

10,000

1,000

100

10

1

Power of Magnification

10

5

10

4

10

3

10

2

10

1

10

0

Numerals

4

2

3

5

2

4

423524 = 4 x 10 5 + 2 x 10 4 + 3 x 10 3 + 5 x 10 2 + 2 x 10 1 + 4 x 10 0

The Power of Magnification for each individual column is derived as, Power of Magnification = Base(Column no - 1)

0 The Power of Magnification for each individual column is derived as, Power of Magnification =

1 - 3

CHAPTER 1 : NUMBER BASES

CMA101

1.5 Conversion from Other Bases to Denary

We can use this column system to convert a number in other bases to its equivalence in Denary.

Example:

Convert 1110012 to denary

Column No

6

5

4

3

2

1

Value

32

16

8

4

2

1

Power of Magnification

2 5

2 4

2 3

2 2

2 1

2 0

Numerals

1

1

1

0

0

1

1110012=

1 x 2 5 + 1 x 2 4 + 1 x 2 3 + 1 x 2 0

 

= 32 + 16 + 8 + 1

= 5710

Example:

Convert 4BEEF816 to denary

 

Column No

6

5

4

3

2

1

Value

1048576

65536

4096

256

16

1

Power of Magnification

16

5

16

4

16 3

16

2

16

1

16

0

Numerals

4

B

E E

F

8

4BEEF816

=

=

4 x 16 5 + 11 x 16 4 + 14 x 16 3 + 14 x 16 2 + 15 x 16 1 + 8 x 16 0

497636910

1.6 Conversion from Denary to Other Bases

To convert a denary number to other bases, we do a repeated division by the desired base until a quotient 0 is obtained.

Example:

Convert 47510 to octal

8

475

 

8

59

remainder

8

7

3

remainder

 

3

0

remainder

7

The octal number is obtained by reading the last integer 7 and upwards to include all remainders; 47510 = 7338

1 - 4

7 The octal number is obtained by reading the last integer 7 and upwards to include

CMA101

CHAPTER 1 : NUMBER BASES

Example:

Convert 47510 to binary

2

 

475

2

 

237

2

 

118

2

 

59

2

 

29

 

2

14

2

7

2

3

2

1

 

0

47510 = 1110110112

remainder

1

remainder

1

remainder

0

remainder

1

remainder

1

remainder

0

remainder

1

remainder

1

remainder

1

1.7 Conversion Among Other Base

We have illustrated the conversions between denary and other bases. How about converting a binary number to an octal number? Or, an octal number to a hexadecimal one?

1.7.1 Binary to Octal

We know that 910 = 10012 and 910 = 118 so, we can conclude that 10012 = 118. To convert a binary number to an octal number in this case will involve a lot of calculations.

Is there a better way to convert these numbers?

Yes. How many binary bits do we need to represent an octal digit?

Is there a better way to convert these numbers? Yes. How many binary bits do we

1 - 5

CHAPTER 1 : NUMBER BASES

CMA101

Octal

000

0

001

1

010

2

011

3

100

4

101

5

110

6

111

7

No. of symbols in octal = 2 no. of binary bits

Binary

We need three binary bits to represent symbols in octal! Likewise, one octal number will produce three binary bits.

To prove it, try whether 3748 = 011 111 1002?

1.7.2 Binary to Hexadecimal

Following the same argument, it is not so difficult to see why we need to have four binary bits to represent one hexadecimal number.

No. of symbols in Hexadecimal = 2 no .of binary bits

Now can you see why 1101011002 = 1AC16?

0001

1010 1100

1

A

C

1.7.3 Conversion Between Octal and Hexadecimal

Since every octal number will produce three binary bits, and every four binary bits will produce one hexadecimal number. We can make use of the binary base as the “conversion medium” to convert a hexadecimal number to an octal number or vice versa. Example

Convert 7338 to a hex no.

Step 1:

Convert 7338 to a binary number. 111 011 011

Step 2:

Step 3:

Rearrange this binary number into 4-bit groups. 0001 1101 1011

Convert this binary number to a hex. 1 D B Hence, 7338 = 1DB1

1 - 6

binary number into 4-bit groups. 0001 1101 1011 Convert this binary number to a hex. 1

CMA101

CHAPTER 1 : NUMBER BASES

1.8 Real Number

CHAPTER 1 : NUMBER BASES

In real numbers, e.g. (4.75)10, the 4 is an integer part while 0.75 is a fractional part. What is the way to convert 0.75 to a binary fraction? The method is to multiply 0.75 by 2 continuously until the fraction becomes zero or the degree of accuracy is satisfied.

4.75 = 4 + 0.75 = (100)2 + (0.11)2 = (100.11)2

2

2

4 0 0.75 * 2 2 0 1.5 * 2 1 0 1.0
4
0
0.75 * 2
2
0
1.5 * 2
1
0
1.0

0.11

Let's look at another example.

(6.1)10 to be converted to binary places.

6.1

=

6 + 0.1

=

(110)2 + (0.000110)2

= (110.000110)2 correct to 6 binary places. 2 6 0 0.1 * 2 2 3
= (110.000110)2 correct to 6 binary places.
2
6
0
0.1
* 2
2
3
1
0.2
* 2
0.4
* 2
1
0.8
* 2
1.6
* 2
1.2
* 2
0.4
0
.
0
0
0
1
1
0

On the other hand, how can we convert (110.000110)2 to denary real numbers?

Method:

i. Write down the value of each bit (binary digit).

ii. Multiply the value by every bit.

iii. Take the sum of products.

4

1

2

1

1

0

2 -1 2 -2 2 -3 2 -4 2 -5 2 -6

.0

0

1

0

4*1 + 2*1 + 0*1 + 0*0.5 + 0*0.25 + 0*0.12 5 + 1*0.0625 + 1*0.03125 +

0*0.015625

= 6.09375

2 -5 2 -6 .0 0 1 0 4*1 + 2*1 + 0*1 + 0*0.5 +

1 - 7

CHAPTER 1 : NUMBER BASES

CMA101

1.9 Octal Arithmetic

We only cover octal addition. The sum of two octal numbers can be reduced by the usual addition algorithm to the repeated addition of two digits (with possibly a carry of 1). The following table shows the addition of Octal number.

++

0

1

2

3

4

5

6

7

0

0

1

2

3

4

5

6

7

1

1

2

3

4

5

6

7

10

2

2

3

4

5

6

7

10

11

3

3

4

5

6

7

10

11

12

4

4

5

6

7

10

11

12

13

5

5

6

7

10

11

12

13

14

6

6

7

10

11

12

13

14

15

7

7

10

11

12

13

14

15

16

The sum of two octal digits, or the sum of two octal digits plus 1, can be obtained by:

i. Finding their decimal sum; and

ii. Modifying the decimal, if it exceeds 7, by subtracting 8 and carrying 1 to the next column.

Example:

58 + 68 + 28 = 158

Modification

+

58

68

28

Decimal sum

-

8

Octal sum

1.10 Hexadecimal Arithmetic

As with the octal system, we cover only hexadecimal addition.

The sum of two hexadecimal digits, or the sum of two hexadecimal digits plus 1, can be obtained by:

i. Finding their decimal sum; and

ii. Modifying the decimal, if it exceeds 15, by subtracting 16 and carrying 1 to the next column.

1 - 8

decimal sum; and ii. Modifying the decimal, if it exceeds 15, by subtracting 16 and carrying

CMA101

CHAPTER 1 : NUMBER BASES

If the base exceeds ten, we need mentally to change each hexadecimal letter digit to its decimal form when finding the decimal sum, and each decimal difference greater than nine to its hexadecimal form when modifying the decimal sum.

A = 10 B = 11 C = 12 D = 13 E = 14 F = 15

Example:

A16 + 916

Decimal sum

Modification

Octal sum

-

+

A16

916

19

16

1316

1.11 Modular Arithmetic

In our daily life, there are many counting/measuring systems around us. We know that 100cm is not the same as 100 inches. It's because the measuring units are different, however, we do not intend to cover the conversions of this kind.

To demonstrate how modular arithmetic works is to give a test first:

“If Peter starts work at 8 o'clock in the morning and works for 8 hours, at what time will Peter finish work?”

4 o'clock in the afternoon, right? But how you worked that one out? Because the clock only has 12 hours, once the shorthand reaches 12, it will restart from 0. The numbers we see on the clock-face must be less than or equal to 12. This is a finite set or finite arithmetics.

To show it mathematically, we add 8 hours to 8 o'clock, and divide 16 by the modules number 12, the remainder 4 will be the answer we want.

 

8

+

8

=

16

(16) mod 12

 

=

4

Example:

(11 + 3 + 7 + 9)mod 12

30/12

 

=

2 remainder 6

30 mod12=

6

  = 4 Example: (11 + 3 + 7 + 9) mod 12 30/12   =

1 - 9

CHAPTER 1 : NUMBER BASES

CMA101

Points to Remember

φ The various sets of numbers include:

Natural numbers

Integers

Rational numbers

Irrational numbers

Real numbers

Complex numbers

φ The higher the precision required the longer the processing time in computer systems.

φ 4 number systems

Decimal (Denary)

Binary

Octal

Hexadecimal

φ Additional of Octal and Hexadecimal

φ Convert from other base to decimal integer

Step 1. Write down the weight of each digit;

Step 2. Multiply each weight and each digit;

Step 3. Take the sum of the product.

φ Convert from decimal integer to other bases

Step 1. Divide the decimal integer by the desired base;

Step 2. Write down the remainder;

Step 3. Repeat dividing until a quotient 0;

Step 4. Read the remainders from bottom upwards.

φ Octal and hexadecimal numbers are used as a shorthand for binary numbers.

φ Each octal digit can be expressed as 3 binary digits

Each hexadecimal digit can be expressed as 4 binary digits.

φ Use modular arithmetic when the data is finite.

1 - 10

hexadecimal digit can be expressed as 4 binary digits. φ Use modular arithmetic when the data

CMA101

CHAPTER 1 : NUMBER BASES

1.12 Past Year Questions

1. Express the number 7478 in:

a. Binary

[

1

]

b. Denary

[

1 ]

c. Hexadecimal

[

1 ]

2. Convert showing all working;

a. 21.625 denary to binary

[

1 ]

b. 2AE hexadecimal to denary

[

1 ]

c. 16.62 octal to binary

[

1 ]

d. 567 octal to binary

[

1 ]

e. 684 denary to hexadecimal

[

1 ]

3. Convert the following:

a. 157 denary to binary

[

1 ]

b. 1100110101 binary to octal

[

1 ]

c. ACD hexadecimal to denary

[

1 ]

d. 2464 octal to hexadecimal

[

1 ]

4. Convert the following:

a. 101 101 101 Binary to Octal

[

1 ]

b. DAB Hexadecimal to Denary

[

1 ]

c. 2839 Denary to Hexadecimal

[

1 ]

d. 7453 Octal to Hexadecimal

[

1 ]

5. Express the denary number 567:

a. in binary

[

1 ]

b. in hexadecimal

[

1 ]

6. Express the number 1038:

a. in binary

[

1 ]

b. hexadecimal

[

1 ]

7. Convert:

a. 274 Octal to DENARY

[

1 ]

b. DA3 Hexadecimal to OCTAL

[

1 ]

1 - 11

1 - 11

CHAPTER 1 : NUMBER BASES

CMA101

8. Convert:

a. ABC Hexadecimal to OCTAL

b. 3974 Denary to HEXADECIMAL

9. Convert:

a. 7456 Octal to HEXADECIMAL

b. 9E7 Hexadecimal to DENARY

10. Convert:

a. 8543 Denary to OCTAL

b. 9AD Hexadecimal to OCTAL

11. Convert:

a. A25 HEXADECIMAL to BINARY

b. 549 DENARY to OCTAL

c. 3527 OCTAL to HEXADECIMAL

12. Convert:

a. 5391 Denary to HEXADECIMAL

b. 6A5 Hexadecimal to OCTAL

13. Convert:

a. 5743 Denary to HEXADECIMAL

b. ABC Hexadecimal to OCTAL

C1003

[

[

[

[

[

[

[

[

[

[

[

[

[

1 ]

1 ]

1 ]

1 ]

1 ]

1 ]

1 ]

1 ]

1 ]

1 ]

1 ]

1 ]

1 ]

14. Convert the following: (You MUST show all workings.)

a. 110100102 to Hexadecimal

b. 54A16 to Denary

c. 10178 to Binary

d. 16710to Binary

15. Convert the following:

a. 1752648to base 16

b. 110110 to base 16

c. 72828 to base 10

d. B0016 + 1F16 to base 2

[

[

[

[

[

[

[

[

2 ]

2 ]

2 ]

2 ]

1 ]

1 ]

2 ]

2 ]

1 - 12

base 16 c. 72 8  2 8 to base 10 d. B00 16 + 1F

CMA101

CHAPTER 1 : NUMBER BASES

16. Express the number 2310 in binary

a.

[

1 ]

b.

Express the number 4610 in binary

[

1 ]

c.

Express the number 9210 in binary

[

1 ]

d.

Express in binary the result of multiplying 1001101112 by 410

[

2 ]

17. Convert the following:

a. 3578 to base 16

[

2 ]

b. 101110to base 16

[

2 ]

c. 504828to base 10

[

2 ]

d. 6A16 + D0016 to base 2

[

2 ]

18. What is the BASE of the number system where 36 + 27 = 65?

[

2 ]

19. By converting to BINARY, evaluate the

HEXADECIMAL expression: 7B + EA. Give your answer in HEXADECIMAL.

[

2 ]

20. Evaluate (7 * 4 + 6 * 5) mod 11

a.

[

1 ]

b.

Solve (3 * p = 8) mod 11

[

2 ]

21. Evaluate (7 * 3 + 5 * 2 + 2 * 1) mod 11

a.

[

1 ]

b.

Evaluate (3 * p) mod 5 for p = 0, 2 and 4

[

2 ]

22. Evaluate (8 * 5 + 7 * 6) mod 11

a.

[

1 ]

b.

Solve (3p = 7) mod 11

[

2 ]

23. Evaluate ((4 * 6) + (35 DIV 4)) MOD 11

[

3 ]

1 - 13

1 - 13