Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Problem Solving using computers Data.. Representation & storage Representation of Numeric data The Binary System.

Similar presentations


Presentation on theme: "1 Problem Solving using computers Data.. Representation & storage Representation of Numeric data The Binary System."— Presentation transcript:

1 1 Problem Solving using computers Data.. Representation & storage Representation of Numeric data The Binary System

2 2 What Types Of Numbers ? Number A representation of the count of things Natural Numbers –The Number 0; –Any number obtained by repeatedly adding a count of 1 to the previous, starting with 0; –Think of them as ‘counting up’ from the 0; Negative Numbers –A value less than 0; –Represents a ‘count down’ from the 0; Integer A Natural Number, a negative of a natural number, or 0. An integer number system is a system for ‘counting things’ in a simple systematic way.

3 3 Problem statement Develop a scheme for representation of numbers using bits (lets focus on positive integer numbers). Can we represent numbers as we did for text data ? (i.e. represent each digit appearing in the number by its corresponding 8-bit ASCII code (Click here ).Click here For example,The representation of 37 will be: 00110011 00110111 3 7 Disadvantage? Non economical. if we are restricted to use bit patterns of length 16 for each number, how many possible numbers can we represent ? Shockingly … only the numbers from 00 to 99, why? Representing numbers by the ASCII codes of their digits is grossly inefficient, any alternatives?

4 4 Lets imitate what we know; The Decimal System How is a positive integer represented in the decimal system? For example why is 375 equal to three hundred and seventy five? 375 = 3 *100 + 7 * 10 + 5*1 = 3*10 2 + 7 * 10 1 + 5*10 0 Another look at 375 375 10 0 10 1 10 2 Position weights digits Number digits 5*10 0 = 5 7*10 1 = 70 3*10 2 = 300 + + 375

5 5 Lets imitate what we know; Decimal System principles A number is a sequence of digits. Any digit must be in the set {0,1,2,3,4,5,6,7,8,9} (that’s why its is called base 10 system). Each digit contributes to value the number represents. The value contributed by a digit equals the product of the digit times the weight of the position of the digit in the number. Position weights are powers of 10; The weight of the right most (least significant position) is 10 0. The weight of any position 10 x, where x is the number of positions to the right of this position. 10 0 10 1 10 2 Position weights Digits of the number 10 3 10 4 70 3

6 6 Lets imitate what we know; From Decimal to binary What if all we had was bits ? Meaning that the only possible digits we can write into a bit are {0,1}? Lets apply all the principles of base 10 system to construct a “base 2 system” 20202020 21212121 22222222 Position weights digits 23232323 24242424 11 0 1

7 7 Converting a number in base 2 to its base 10 equivalent Example The number 100101 represented in base 2 system (written (100101) 2 ) = 1*2 0 + 0*2 1 + 1*2 2 + 0*2 3 + 0*2 4 + 1*2 5 (37) 10

8 8 Converting a number in base 10 to its base 2 equivalent (125) 10 = (? ) 2 (i.e. the number 125 in base 10 is equal to what in base 2?) There is a standard algorithm we can apply to answer this question: –(1) Start with your number, call it n, in base 10; –(2) Divide n by 2 and record the remainder; –(3) If the quotient = 0 stop, else Assign the quotient value to n, and go to step 2; When you stop the remainders recorded will be the digits of the number in base 2 in the positions from rightmost to leftmost; Lets apply this algorithm to an example.

9 9 Converting a number in base 10 to its base 2 equivalent (125) 10 = (? ) 2 Thus (125) 10 = (1111101) 2

10 10 Base 2 System Versus ASCII encoding of digits Assume can only use 16 bits to represent each positive integer, how many different numbers can we represent: –Using the ASCII encoding of digits? –Using base 2 system? Answer –Using ASCII encoding (only the number from 0 – 99 can be represented; a total of 100 distinct numbers) –Using Base 2 system We have 2 16 distinct bit patterns; each can be used to represent a distinct number; a total of 65536 distinct numbers The numbers will be in the range: zero (0000000000000000) 2 to 65535 (1111111111111111) 2

11 11 Base 2 System Arithmetic Addition We represent Numbers because we need to do Arithmetic operations on them; Can we do arithmetic on numbers represented in base 2 ? Yes Consider Addition; When we first did it in elementary school we had to learn and memorize addition facts For the binary system the following are the addition facts 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 (i.e. 0 and carry 1)


Download ppt "1 Problem Solving using computers Data.. Representation & storage Representation of Numeric data The Binary System."

Similar presentations


Ads by Google