Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Systems - Part II

Similar presentations


Presentation on theme: "Number Systems - Part II"— Presentation transcript:

1 Number Systems - Part II
CS 215 Lecture # 6

2 Conversion from Decimal
Let N be the number to be converted. We can write N as N = q*b + r where q = quotient b = the base into which N is to be converted r = remainder

3 Example 6.1 Convert 8010 to binary (base 2) 80 = 40*2 + 0
40 = 20*2 + 0 20 = 10*2 + 0 10 = 5*2 + 0 5 = 2*2 + 1 2 = 1*2 + 0 1 = 0*2 + 1 Answer:

4 Example 6.2 Convert 8010 to octal(base 8) 80 = 10*8 + 0 10 = 1*8 + 2
10 = 1*8 + 2 1 = 0*8 + 1 Answer: 8010 = 1208 Also, from binary: 8010 = = = 120

5 Example 6.3 Convert 8010 to hexadecimal(base 16) 80 = 5*16 + 0
5 = 0*16 + 5 Answer: 8010 = 5016 Also, from binary: 8010 = = = 50

6 Conversion from Decimal
Decimal  Binary or Hexadecimal Repeated division by 2 or 16 Example: Convert 292 to hexadecimal. 292/16 = 18 R 4 18/16 = 1 R 2 1/16 = 0 R 1 292 = 12416 When the quotient is less than 16, the process ends

7 Conversion from Decimal
Convert 42 to hexadecimal 42/16 = 2 R 10 (but 10 = a16) 2/16 = 0 R = 2a16 Convert 109 to binary 109/2 = 54 R 1 54/2 = 27 R 0 27/2 = 13 R 1 13/2 = 6 R 1 6/2 = 3 R 0 3/2 = 1 R 1 1/2 = 0 R =

8 Shortcut: convert to hexadecimal
It is sometimes easier to convert from binary to hexadecimal, then to decimal, instead of converting directly to decimal = = a b = 3*16^3 + 10*16^2 + 11*16 + 6 = 3* * = = = 14940

9 Shortcut: convert to hexadecimal
The converse is also true: converting from decimal to hexadecimal, then to binary generally requires far fewer steps than converting directly to binary 278/16 = 17 R 6 17/16 = 1 R 1 1/16 = 0 R 1 278 = = =

10 Example 6.4 Convert the following: 5010 = ____16 5010 = ____8
5010 = ____2 5010 = ____5

11 Conversion of Fractions
A decimal improper fraction a/b is converted into a different base b by converting it into a mixed fraction a/b = d e/f e.g. 13/8 = 1 5/8 convert d into the required base using the techniques we have already discussed convert e/f (now a proper fraction) into the required base by following the steps below the answer is in the format ...f1f0.f-1f-2...

12 Example 6.5 Convert 2 5/8 to binary 2*(5/8) = 1 + 1/4
2*(1/4) = 0 + 1/2 2*(1/2) = 1 + 0 Answer:

13 Example 6.6 Convert 3.6 to binary 2*.6 = 1 + .2 2*.2 = 0 + .4
2*.4 = 2*.8 = Answer:

14 Converting back into decimal
10.101 fraction part = 1*(1/2)1 + 0*(1/2)2 + 1*(1/2)3 = .625 or 5/8 integer part = 1*(21) + 0*(20) = 2 Answer: 2 5/8

15 Scientific Notation Given a number N, we can express N as N = s*rx
where s = mantissa or significand r = radix x = exponent

16 The mantissa can be made an integer by multiplying it with a fixed power of the radix and subtracting the appropriate integer constant from the exponent For example, 2.358 * 101 = 2358 * 10-2

17 Normalization Standard scientific notation defines the normal form to meet the following rule. 1 £ s < r where s = significand r = radix A representation is in normal form if the radix point occurs just to the right of the first significant symbol

18 Example 6.7 2358 * = * 101 1525 * = * 102

19 Representing Numbers Choosing an appropriate representation is a critical decision a computer designer has to make The chosen representation must allow for efficient execution of primitive operations For general-purpose computers, the representation must allow efficient algorithms for addition of two integers determination of additive inverse

20 Representing Numbers With a sequence of N bits, there are 2N unique representations Each memory cell can hold N bits The size of the memory cell determines the number of unique values that can be represented The cost of performing operations also increases as the size of the memory cell increases It is reasonable to select a memory cell size such that numbers that are frequently used are represented

21 Binary Representation
The binary, weighted positional notation is the natural way to represent non-negative numbers. MAL numbers the bits from right to left, beginning with 0 as the least significant digit.

22 Modulo Arithmetic Consider the set of number {0, … ,7}
Suppose all arithmetic operations were finished by taking the result modulo 8 3 + 6 = 9, 9 mod 8 = 1 3 + 6 = 1 3*5 = 15, 15 mod 8 = 7 3 * 5 = 7 1 2 3 4 5 6 7

23 Modulo Arithmetic: Additive Inverse
What is the additive inverse of 7? 7 + x = 0 7 + 1 = 0 0 and 4 are their own additive inverses 1 2 3 4 5 6 7


Download ppt "Number Systems - Part II"

Similar presentations


Ads by Google