Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Systems - Part I CS 215 Lecture # 5.

Similar presentations


Presentation on theme: "Number Systems - Part I CS 215 Lecture # 5."— Presentation transcript:

1 Number Systems - Part I CS 215 Lecture # 5

2 Motivation The representation of numbers is made difficult because of the discrete nature of computer representation Not all numbers can be represented in a computer The chosen method of representation affects the ease by which arithmetic operations are performed

3 Unary Representation In a unary representation, the number one is represented by a single mark, the number two by two marks, etc. Unary has limitations: the number of symbols necessary to represent a number grows directly with the value negative numbers can not be represented

4 Roman Numerals Roman numerals are sorted by decreasing values
A symbol representing a smaller value preceding a symbol representing a larger value means we have to subtract the smaller value from the larger value Only a single smaller symbol may precede a larger one Only symbols representing powers of ten (I,X,C) may be placed out of order I 1 V 5 X 10 L 50 C 100 D 500 M 1000

5 Addition in Roman Numerals?
A possible algorithm Convert all position sensitive symbols into position insensitive form Sort by values of symbols Merge the two position-insensitive representations into a single position-insensitive representation Combine lowest-value types into higher value-types Create legal Roman numerals by converting back to the unique format

6 Example 5.1 XIX (19) + MXMV (1995) XIX = XVIIII MXMV = MDCCCCLXXXXV
XVIIII + MDCCCCLXXXXV = MDCCCCLXXXXXVVIIII MDCCCCLXXXXXVVIIII = MDCCCCLXXXXXXIIII = MDCCCCLLXIIII = MDCCCCCXIIII = MDCCCCCXIIII = MDDXIIII = MMXIIII MMXIIII = MMXIV (2014)

7 Weighted Positional Notation
Use the position of the symbol to indicate the value By assigning each position the appropriate power of the base, we can get a unique representation of numbers in that base Decimal System (Base 10) Given a sequence of n digits d0,d1,…,dn-1 dn-1.10n-1 + … + d d0.100

8 In general, given a sequence of n digits s0,s1,…,sn-1 and a base b,
sn-1.bn-1 + … + s1.b1 + s0.b0 yields a unique integer N s0 is the least significant digit sn-1 is the most significant digit The most significant symbol can not be zero

9 Any positive integer value can be used as the base or radix for a weighted positional notation
For bases less than or equal to 10, a subset of the ten decimal digits can be used, e.g., binary (base 2) and octal (base 8) For bases more than 10, new symbols will have to be introduced, e.g., hexadecimal (base16)

10 We use a subscript to indicate the base of the number when we are writing.
In programming languages, octal representation may be preceded with a zero (0), e.g., 033. A hexadecimal representation may be preceded with 0x, e.g., 0x1b SAL and MAL use these for hexadecimal and decimal numbers; octal is not recognized

11 Representations in different radices
binary octal hexa decimal F 15

12 Hexadecimal and Octal Hex Octal Decimal Binary 1 1 1 0001 2 2 2 0010
A B C D E F

13 Discriminating only between two symbols would be far cheaper in digital circuitry than three, four, etc. thus binary is the chosen representation for computers. Since bits can be grouped into three to obtain octal value and into four to obtain hexadecimal value, it is much easier for humans to work with octal and hexadecimal representations.

14 hexadecimal, octal, and binary
To convert the octal or hexadecimal representation from binary simply group them starting from the least significant bit into three for octal and into four for hexadecimal Example octal hexa binary B hence: is 338 or 1B16 or 0x1B or 033

15 Example 5.2 Convert 11101 to octal _________
Convert to hexadecimal _________ Convert to octal _________ Convert to hexadecimal _________

16 Zero and negative numbers
To represent zero, we violate the rule that says the most significant symbol can not be zero, and use the single symbol ‘0’ We can specify, a symbol ‘-’ that is placed only at the beginning of the sequence to signify negative numbers The absence of or presence of the symbol ‘+’ signify positive numbers

17 Conversion into Decimal
Given a sequence of base-r digits sn-1...s1s0 convert the sequence into a decimal number N using: N = sn-1.bn-1 + … + s1.b1 + s0.b0

18 Example 5.3 Convert 10 01102 to decimal.
= 3810 Convert 3b216 to decimal. N = 3* * *160 = 94610 Convert 3708 to decimal. N = 3*82 + 7*81 + 0*80 = = 24810

19 Example 5.4 Convert the following to decimal: 1. 3467 _______
_______ _______ _______ 5. 6A16 _______ _______


Download ppt "Number Systems - Part I CS 215 Lecture # 5."

Similar presentations


Ads by Google