Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Representation

Similar presentations


Presentation on theme: "Number Representation"— Presentation transcript:

1 Number Representation
CHAPTER 3

2 3.1 Decimal & binary

3 Decimal System The position in the decimal numbering system is meaningful The base is 10.

4 Binary System

5 Binary System There are only two digits in the binary system 0 and 1.
The base is 2. Each position is double the previous position.

6 3.2 Conversion

7 Before discussing how numbers in the form of bit patterns stored in memory…
We should understand how to convert a number from the decimal system to the binary system, and vice versa. 45

8 Binary to Decimal Conversion

9 Convert the binary number 10011 to decimal.
Example 1 Convert the binary number to decimal. Solution Write out the bits and their weights. Multiply the bit by its corresponding weight and record the result. At the end, add the results to get the decimal number. Binary Weights Decimal

10 Decimal to binary conversion

11 Convert the decimal number 35 to binary.
Example 1 Convert the decimal number 35 to binary. Solution Write out the number at the right corner. Divide the number continuously by 2 and write the quotient and the remainder. The quotients move to the left, and the remainder is recorded under each quotient. Stop when the quotient is zero. 0  1  2  4  8  1735 Decimal Binary

12 3.3 Integer Representation

13 Integer Representation
Integer Number: is a whole number without fractions, it can be positive or negative

14 Integer Representation
Integers range between negative infinity (– ∞) and positive infinity (+ ∞) But can a computer store all the integers in between?

15 Integer Representation
Unsigned Signed Sign and Magnitude One’s Complement Two’s Complement

16 Unsigned Integer Unsigned Integer: is an integer without a sign and ranges between 0 and + ∞

17 Range: 0  (2N -1) Unsigned Integer
Most computers define a constant called the maximum unsigned integer Unsigned integers range between 0 and this constant The maximum unsigned integer depends on the number of bits allocated to represent the unsigned integer in a computer (N) Range:  (2N -1)

18 Range -------------------------------------
Unsigned Integer # of Bits 8 16 Range ,535 Table Range of unsigned integers

19 Unsigned Integer An input device stores an unsigned integer using the following steps: The integer is changed to binary. If the number of bits is less than N, 0s are added to the left of the binary number so that there is a total of N bits.

20 Example 1 Store 7 in an 8-bit memory location using unsigned representation. First change the integer to binary, (111)2. Add five 0s to make a total of N (8) bits, ( )2. The integer is stored in the memory location. Solution

21 Store 258 in an 16-bit memory location using unsigned representation.
Example 2 Store 258 in an 16-bit memory location using unsigned representation. First change the integer to binary ( )2. Add seven 0s to make a total of N (16) bits, ( )2. The integer is stored in the memory location. Solution

22 Try to store an unsigned integer Such as 256 in an 8-bit memory
What will happen if you Try to store an unsigned integer Such as 256 in an 8-bit memory Location ? Overflow occurs if the decimal is out of range (if binary bits > n )

23 Unsigned Integer Table 3.2 Example of storing unsigned integers in
two different computers Decimal 7 234 258 24,760 1,245,678 8-bit allocation overflow 16-bit allocation overflow

24 representation in decimal?
Interpretation How do you interpret an Unsigned Binary representation in decimal?

25 the binary integer is converted to the unsigned integer 43
Example 3 Interpret in decimal if the number was stored as an unsigned integer the binary integer is converted to the unsigned integer 43 Solution

26 Unsigned Integer Applications
Counting : you don’t need negative numbers to count and usually start from 0 or 1 going up Addressing: sometimes computers store the address of a memory location inside another memory location, addresses are positive numbers starting from 0

27 Integer Representation
Unsigned Signed Sign and Magnitude One’s Complement Two’s Complement

28 Sign-and-magnitude representation
Signed Integer: is an integer with a sign either + or -

29 Sign-and-magnitude representation
Storing an integer in a sign-and-magnitude format requires 1(the leftmost) bit to represent the sign (0 for positive and 1 for negative) Range : 0  -(2N-1 -1)…. +(2N-1 -1)

30 Sign-and-magnitude representation
Table Range of sign-and-magnitude integers # of Bits 8 16 32 Range -2,147,483, ,147,483,647

31 Sign-and-magnitude representation
There are two 0s in sign-and-magnitude representation: positive and negative. In an 8-bit allocation: +0  

32 Sign-and-magnitude representation
Storing sign-and-magnitude signed integer process: The integer is changed to binary, (the sign is ignored). If the number of bits is less than N-1, 0s are added to the left of the number so that there will be a total of N- 1 bits . If the number is positive, 0 is added to the left (to make it N bits). But if the number is negative, 1 is added to the left (to make it N bits)

33 Example 4 Store +7 in an 8-bit memory location using sign-and- magnitude representation. The integer is changed to binary (111). Add 4 0s to make a total of N-1 (7) bits, Add an extra 0 (in bold) to represent the positive sign Solution

34 Add an extra 1 because the number is negative.
Example 5 Store –258 in a 16-bit memory location using sign- and-magnitude representation First change the number to binary Add six 0s to make a total of N-1 (15) bits, Add an extra 1 because the number is negative. Solution

35 ------------------------------
Table 3.4 Example of storing sign-and-magnitude integers in two computers Decimal +7 -124 +258 -24,760 8-bit allocation overflow 16-bit allocation

36 representation in decimal?
Interpretation How do you interpret a Signed Binary representation in decimal?

37 Sign-and-magnitude Interpretation
Ignore the first (leftmost) bit Change the N -1 bits from binary to decimal Attach a + or – sign to the number based on the leftmost bit.

38 Example 6 Interpret to decimal if the number was stored as a sign-and-magnitude integer. Ignoring the leftmost bit, the remaining bit are This number in decimal is 59. the leftmost bit is 1 so the number is – 59. Solution

39 Signed Integer Applications
The sign-and-magnitude representation is not used now by computers because: Operations: such as subtraction and addition is not straightforward for this representation. Uncomfortable in programming: because there are two 0s in this representation

40 Signed Integer Applications
However.. The advantage of this representation is: Transformation: from decimal to binary and vice versa which makes it convenient for applications that don’t need operations on numbers Ex: Converting Audio (analog signals) to digital signals.


Download ppt "Number Representation"

Similar presentations


Ads by Google