Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Representation and Computer Arithmetic

Similar presentations


Presentation on theme: "Binary Representation and Computer Arithmetic"— Presentation transcript:

1 Binary Representation and Computer Arithmetic

2 DECIMAL and BINARY system
The Decimal System This uses ten digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) to represent numbers The Binary System uses just two digits, 0 and 1 easier for a computer to distinguish between two different voltage levels (than ten)

3 POSITIONAL NOTATION (in decimal)
Consider the decimal number 5237. Positional Name thousands hundreds tens units Positional Weight 103 102 101 100 Value 1 000 10 1 5 2 3 7 5 237 5 x x x x 1

4 POSITIONAL NOTATION (in binary)
Consider the byte Positional Weight 27 26 25 24 23 22 21 20 Value 128 64 32 16 8 4 2 1 Number  Positional Notation = 1x x64 + 0x32 + 0x16 + 0x8 + 1x4 + 0x2 + 1x1 = 197  Note the LSD in is the right most digit which is 1 and the MSD is the left most digit which is 1.

5 Representing Integers in Binary
ASCII codes are pure or true binary numbers.  By that we mean there is no positive or negative sign attached to these numbers. We are now going to look at representing integers in binary.

6 Representing Integers in Binary
Here are some of the challenges we face when we move to representing integers in binary: 1.  Integers can be positive or negative.  2. Must have a unique representation.   3. Should be able to add and subtract them  4.  Operations must be efficient ( using the smallest number of circuits possible) 

7 INTEGER REPRESENTATIONS
There are 4 commonly known (1 not common) integer representations. All have been used at various times for various reasons. 1. unsigned 2. sign magnitude 3. one's complement 4. two's complement 5. biased (not commonly known)

8 UNSIGNED BINARY NUMBER SYSTEM
The standard binary encoding already given only positive values range: 0 to 2**n - 1, for n bits example: 4 bits, values 0 to 15 n=4, 2**4 -1 is 15

9 Sign-Magnitude Binary Number System
The sign and magnitude number system is a simple binary code system used to represent positive and negative integers.  In this system, the first bit (the MSB) in a binary representation is a sign bit (0 for positive and 1 for negative)  followed by the  magnitude bits.  

10 Sign-Magnitude Binary Number System
Example 0101 represents the number +5.  The most significant bit (MSB) =0.  The 0 indicates the number is positive. The remaining 3 bits represent the magnitude of the number.  The decimal value of binary 101 is = 5. Therefore, 0101, using a 4-bit sign-magnitude convention is the integer +5

11 PROBLEM How many positive binary numbers can be represented in a nibble using the sign-magnitude notation? How many positive binary numbers can be represented in a byte using the sign-magnitude notation?

12 Representation of Negative Integers using Sign-Magnitude Notation
Example When an 8-bit sign-magnitude convention for representing numbers is used, the number represents the negative integer -55. The first bit, the MSB, is 1 indicating the integer is negative. The next 7 bits represent the magnitude of the integer. Binary has decimal value  = 55.

13 The 1's Complement form Example
The 1's complement representation in binary of a positive integer is same as the sign-magnitude representation of that integer. Example Using a byte, the 1's complement in binary of  +84 is

14 The 1's Complement in Binary of a Negative Integer
Rule:  The 1's complement in binary of a negative integer is obtained by subtracting its magnitude  from 2n -1 where n is the number of bits used to store the integer in binary.

15 BINARY ARITHMETIC

16 BINARY ADDITION Rule 1 Rule 2 Rule 3 Rule 4 Rule 5 +0 +1 1 + 1 1 0 11

17 BINARY ADDITION View online lesson

18 BINARY ADDITION Example Add these binary numbers: 1100 (12)+
             (12)+       +    1101  (13)               (25)   

19 BINARY SUBTRACTION Rule 1 Rule 2 Rule 3 Rule 4 - 0 1 - 1

20 BINARY SUBTRACTION View online lesson

21 BINARY SUBTRACTION Example Subtract these binary numbers: 1101 (13)-
             (13)-       +   0110  ( 6)          0111    (7)   

22 The 1's Complement in Binary of a Negative Integer
Example Store the integer -36 in a byte in 1's complement form. Step 1:    =     [convert the magnitude of the integer to binary] Step 2:                                              [A byte contains 8 bits. Therefore, subtract from 28-1= 255.  In binary 255 is ]

23 EASY WAY Determine the 1's complement of a negative integer Determine the 1's complement of the corresponding positive integer invert all bits.

24 EXAMPLE +57 stored in a byte in 1's complement form is 0011 1001.
Using a byte, find the 1's complement of -57. +57 stored in a byte in 1's complement form is  Invert all bits to determine the 1's complement of -57 to be

25 Two's Complement Notation
The 2's Complement in Binary of a Positive Integer same as sign-magnitude notation

26 Two's Complement Notation
The 2's Complement of a Negative Integer First, we write the positive value of the number in binary. Next, we reverse each bit to get the 1's complement. Last, we add 1 to the number.

27 Example Store -27 in a byte using 2's complement notation.
Step 1:  +27 in binary is Step 2:  Invert bits to yield   Then the 1's complement of -27 is Step 3:  Add 1 to the 1's complement:                                       +           1                    The 2's complement of -27 is

28 Binary Arithmetic Subtraction with one’s complement
Subtraction with two’s complement

29 Fractions Converting a fractional decimal value to binary

30 Floating Point Arithmetic
Floating point arithmetic derives its name from something that happens when you use exponential notation. Consider the number 123: it can be written using exponential notation as: 1.23 * 10 2 12.3 * 10 1 123 * 10 0 .123 * 10 3 1230 * 10 -1

31 Floating Point Arithmetic
All of these representations of the number 123 are numerically equivalent. They differ only in where the decimal point appears in the number. The decimal point "floats" within the number as the exponent is changed. This phenomenon gives floating point numbers their name.

32 Floating Point Arithmetic
The first representation, 1.23 * 10 2, is in a form called "scientific notation“ In scientific notation, the significand is always a number greater than or equal to 1 and less than 10. (normalization)

33 Floating Point Number A floating-point number is often stored as three parts: A significand or mantissa (indicating the digits that define the number's magnitude) An exponent or scale (indicating the position of the radix point) A sign (indicating whether the number is positive or negative)

34 Floating Point Arithmetic
The exponent does not always indicate a power of ten; sometimes powers of sixteen are used instead, or, most commonly of all, powers of two The real number is equal to -1.25 x 10^-1 if powers of ten are used, -2 x 16^-1 if powers of sixteen are used, -1 x 2^-3 if powers of two are used. The absolute value of the mantissa is, however, always greater than or equal to 1 and less than the base of numeration.

35 Floating Point Formats
Over the years, floating point formats in computers have not exactly been standardized. While the IEEE (Institute of Electrical and Electronics Engineers) has developed standards in this area, they have not been universally adopted.

36 In the IEEE single-precision representation of a real number
One bit is reserved for the sign, and it is set to 0 for a positive number and to 1 for a negative one. A representation of the exponent is stored in the next eight bits. The remaining twenty-three bits are occupied by a representation of the mantissa of the number.

37 IEEE 754 Standard (32 bits) Sign bit (1 bit) Mantissa (23 bits)
31 30 29 28 27 26 25 24 23 22 21 2 1 Sign bit (1 bit) Mantissa (23 bits) Exponent (8 bits)

38 IEEE 754 Standard (32 bits) Sign bit = 0 or 1
The exponent, which is a signed integer in the range from -126 to 127, is represented as a biased value. (127 is the bias used) Only the part of the mantissa that comes after the binary point is actually stored. This suppressed digit at the beginning of the mantissa is called the ``hidden bit.''

39 Floating Point Arithmetic
In a binary computer, all numbers are stored in base 2 instead of base 10 The absolute value of the mantissa is, however, always greater than or equal to 1 and less than 2.

40 EXAMPLE Find the IEEE single-precision representation of 5.75.
The sign bit is 0, since the number is positive (5)10 = (101)2 To convert 0.75 do repeated multiplication

41 EXAMPLE .75 X 2 = 1.5 -------- 1 .5X2 = 1.0 ----------1
 (stop) (.75)10 = (.11)2

42 EXAMPLE (5.75)10 = (101.11)2 Normalizing 101.11 --- 1 . 0111 X 22
Hidden bit mantissa Exponent Adding bias to the exponent 127+2 = 129 (129)10 = ( )2

43 And the result…. Lining up, we get

44 More Examples Convert from Decimal to Binary


Download ppt "Binary Representation and Computer Arithmetic"

Similar presentations


Ads by Google