UNIT - 3
Use of Complements to represent negative
numbers
SIGN MAGNITUDE REPRESENTATION
• One method of representing negative numbers is sign-magnitude.
• Sign-magnitude representation uses the most significant bit of the number to indicate the sign.
• A negative number is the 7-bit binary representation of the positive number with the most significant bit set to one.
• 8-bit binary number (a byte) can have a value ranging from 0 (000000002) to 255 (111111112), that is 28 = 256 different combinations
SIGN MAGNITUDE REPRESENTATION
• Mathematical numbers are generally made up of a sign and a value (magnitude) in which the sign indicates whether the number is positive, ( + ) or negative, ( – ) with the value indicating the size of the number, for example 23, +156 or -274.
• Sign-magnitude notation is the simplest and one of the most common methods of representing positive and negative numbers either side of zero, (0). Thus negative numbers are obtained simply by changing the sign of the corresponding positive number as each positive or unsigned number will have a signed opposite, for example, +2 and -2, +10 and -10, etc.
SIGN MAGNITUDE REPRESENTATION
• Presenting numbers is this fashion is called “sign-magnitude”
representation since the left most digit (most significant bit) can be used to indicate the sign and the remaining digits the magnitude or value of the number.
• If the sign bit is “0”, this means the number is positive in value. If the sign bit is “1”, then the number is negative in value. The remaining bits in the number are used to represent the magnitude of the binary number in the usual unsigned binary number format way.
SIGN MAGNITUDE REPRESENTATION
• The Sign-and-Magnitude (SM) notation stores positive and negative values by dividing the “n” total bits into two parts: 1 bit for the sign and n–1 bits for the value which is a pure binary number. For example, the decimal number 53 can be expressed as an 8-bit signed binary number as follows.
SIGN MAGNITUDE REPRESENTATION
SIGN MAGNITUDE REPRESENTATION
• With 8-bit sign-magnitude representation, what positive integers can be represented and what negative integers can be represented?
SIGN MAGNITUDE REPRESENTATION
•
Problems with Sign-Magnitude
• There are problems with sign-magnitude representation of integers. Let us use 8-bit sign-magnitude for examples.
• The leftmost bit is used for the sign, which leaves seven bits for the magnitude. The magnitude uses 7-bit unsigned binary, which can represent 010 (as 000 0000) up to 12710(as 111 1111). The eighth bit makes these positive or negative, resulting in -12710, ... -0, 0, ... 12710.
• One pattern corresponds to "minus zero", 1000 0000. Another corresponds to "plus zero", 0000 0000.
Cont.…
• There are several problems with sign-magnitude. It works well for representing positive and negative integers (although the two zeros are bothersome). But it does not work well in computation. A good representation method (for integers or for anything) must not only be able to represent the objects of interest, but must also support operations on those objects.
• This is what is wrong with Roman Numerals: they can represent positive integers, but they are very poor when used in computation.
Cont.…
• There are several problems with sign-magnitude. It works well for representing positive and negative integers (although the two zeros are bothersome). But it does not work well in computation. A good representation method (for integers or for anything) must not only be able to represent the objects of interest, but must also support operations on those objects.
• This is what is wrong with Roman Numerals: they can represent positive integers, but they are very poor when used in computation.
Cont.…
Ones' complement
• ones' complement can be used to represent negative numbers. The ones' complement form of a negative binary number is the complement of its positive counterpart, which can be obtained by applying the NOT to the positive counterpart.
• Like sign-magnitude representation, ones' complement has two representations of 0: 00000000 (+0) and 11111111 (−0). As an example, the ones' complement of 00101011 (43) is 11010100 (−43).
• The range of signed numbers using ones' complement in a conventional 8-bit byte is −127 to +127.
Ones' complement
1's Complement Addition
• To add two numbers represented in this system, we use the conventional binary addition, but it is then necessary to add any resulting carry back into the resulting sum. To see why this is necessary, consider the following example showing the case of the addition of −1 (11111110) to +2 (00000010).
• Case I: When the positive number has greater magnitude.
• In this case addition of numbers is performed after taking 1’s complement of the negative number and the end-around carry of the sum is added to the least significant bit.
• When negative numbers are expressed in binary addition using 2’s complement the addition of binary numbers becomes easier. This operation is almost similar to that in 1’s complement system and is explained with examples given below:
A. Addition of a positive number and a negative number.
We consider the following cases.
Case I: When the positive number has a greater magnitude
In this case the carry which will be generated is discarded and the final result is the result of addition.
• Case II: When the negative number is greater.
• When the negative numbers is greater no carry will be generated in the sign bit. The result of addition will be negative and the final result is obtained by taking 2’s complement of the magnitude bits of the result.
Binary Codes
•
The codes are broadly categorized into following two categories.
•
Weighted Codes
•
Non-Weighted Codes
Binary – Weighted Codes
• Weighted binary codes are those binary codes which obey the positional weight principle. Each position of the number represents a specific weight. Several systems of the codes are used to express the decimal digits 0 through 9. In these codes each decimal digit is represented by a group of four bits.
Binary – Non Weighted Codes
• In this type of binary codes, the positional weights are not assigned.
The examples of non-weighted codes are
• Excess-3 code and
• Gray code.
• Excess-3 code
• The Excess-3 code is also called as XS-3 code. It is non-weighted code used to express decimal numbers. The Excess-3 code words are derived from the 8421 BCD code words adding (0011)2 or (3)10 to each code word in 8421.
Excess -3 code
One should note that corresponding to given Excess-3 code, the equivalent decimal number can be determined by first splitting the number into four-bit groups, starting from radix point and then subtracting 0011 from each four-bit group. This gives us 8421 BCD equivalent of the given Excess-3 code, which can then be converted into the equivalent decimal number.
For example; Let us suppose we want to determine the decimal equivalent for the Excess-3 code 1000110. First we make group of 4 bits starting from radix point.
Subtracting 0011 from each group, we obtain the new number as 00010011. Its decimal equivalent is 13.
Therefore, (1000110) Excess-3= (13)10
Gray Code
• It has a very special feature that, only one bit will change each time the decimal number is incremented.
• As only one bit changes at a time, the gray code is called as a unit distance code.
• The gray code is a cyclic code. Gray code cannot be used for arithmetic operation.
•
Binary to gray code conversion is a very simple process.
There are several steps to do this types of conversions. Steps given below elaborate on the idea on this type of conversion.
1. The M.S.B. of the gray code will be exactly equal to the first bit of the given binary number.
2. Now the second bit of the code will be exclusive-or of the first and second bit of the given binary number, i.e if both the bits are same the result will be 0 and if they are different the result will be 1.
3. The third bit of gray code will be equal to the exclusive-or of the second and third bit of the given binary number. Thus the Binary to gray code conversion goes on.
Gray Code to Binary Conversion
Gray code to binary conversion is again very simple and easy process.
Following steps can make your idea clear on this type of conversions.
1. The M.S.B of the binary number will be equal to the M.S.B of the given gray code.
2. Now if the second gray bit is 0 the second binary bit will be same as the previous or the first bit. If the gray bit is 1 the second binary bit will alter. If it was 1 it will be 0 and if it was 0 it will be 1.
3. This step is continued for all the bits to do Gray code to binary conversion.
The M.S.B of the binary will be 0 as the M.S.B of gray is 0. Now move to the next gray bit. As it is 1 the previous binary bit will alter i.e it will be 1, thus the second binary bit will be 1. Next look at the third bit of the gray code. It is again 1 thus the previous bit i.e the second binary bit will again alter and the third bit of the binary number will be 0. Now, 4th bit of the given gray is 0 so the previous binary bit will be unchanged, i.e 4th binary bit will be 0. Now again the 5th grey bit is 1 thus the previous binary bit will alter, it will be 1 from 0. Therefore the equivalent Binary number in case of gray code to binary conversion will be (01001).
Binary Coded Decimal (BCD) code
• In this code each decimal digit is represented by a 4-bit binary number. BCD is a way to express each of the decimal digits with a binary code. In the BCD, with four bits we can represent sixteen numbers (0000 to 1111). But in BCD code only first ten of these are used (0000 to 1001). The remaining six code combinations i.e. 1010 to 1111 are invalid in BCD.
Binary Coded Decimal (BCD) code
Advantages of BCD Codes
• It is very similar to binary system.
• We need to remember binary equivalent of decimal numbers 0 to 9 only.
Disadvantages of BCD Codes
• BCD needs more number of bits than binary to represent the decimal number. So BCD is less efficient than binary.
Alphanumeric codes | ASCII code | EBCDIC code | UNICODE
• Alphanumeric codes are sometimes called character codes due to their certain properties.
• Now these codes are basically binary codes. We can write alphanumeric data, letters of the alphabet, numbers, mathematical symbols and punctuation marks by this code which can be easily understandable and can be processed by the computers.
• Input output devices such as keyboards, monitors, mouse can be interfaced using these codes.
• 12-bit Hollerith code is the better known and perhaps the first effective code in the days of evolving computers in early days.
During this period punch cards were used as the inputting and outputting data. But nowadays these codes are termed obsolete as many other modern codes have evolved. The most common alphanumeric codes used these days are ASCII code, EBCDIC code and Unicode.
ASCII code
The full form of ASCII code is American Standard Code for Information Interchange. It is a seven bit code based on the English alphabet. In 1967 this code was first published and since then it is being modified and updated.
It is able to represent 27 = 128 codes as it is a seven bit code. Currently a total number of 95 printable characters are represented by this code including 26 upper case letters (A - Z), 26 lower case letters (a - z), 10 numerals (0 - 9) and there are 33 special characters which include mathematical symbols, punctuation marks and space characters. The latest development in the field of ASCII code is the development of 8 bit code which is known as US ASCII-8 or ASCII-8. As it is an 8 bit code it can represent 28 = 256 characters.
ASCII code
ASCII code
EBCDIC code
The EBCDIC stands for Extended Binary Coded Decimal Interchange Code. IBM invented this code to extend the Binary Coded Decimal which existed at that time. All the IBM computers and peripherals use this code. It is an 8 bit code and therefore can accommodate 256 characters. Below is given some characters of EBCDIC code to get familiar with it.
EBCDIC code
Unicode
Unicode is the newest concept in digital coding. In Unicode every number has a unique character. Leading technological giants have adopted this code for its uniqueness.