In this article, we deal with the first two of the following key skills that build up to understanding the floating point system:
- Define and identify the most and least significant bits in a word. Count how many combinations are possible in a word given its bit length.
- Encode a positive integer in binary. Decode an unsigned integer to decimal.
- Encode an integer in two's complement notation. Decode a signed integer to decimal.
- Use sign extension to expand the number of bits in a word. Explain the mathematics.
- Convert a decimal fraction to binary. Explain why this does not require any particular encoding scheme, such as a floating point standard.
Definition: The most significant bit (MSB) is, in unsigned representation, the bit position associated with the greatest absolute value. Also, in two's complement representation, the bit position that changes the sign of a number.
Definition: The least significant bit (LSB) is the bit position that has the least value associated, that is, the value of 1.
Let's say we have a 32-bit machine that deals with 32-bit words. Each word is a string of four octets (bytes), so there are 32 bits in it. Then, generally, bit position 0 is the LSB, and bit position 31 is the MSB.
Bit position n has the value of 2n, so, for instance, the number
1010 (unsigned) will be equal to 23 + 21 = 8 + 1 = 9. In this instance, the rightmost bit is the LSB and the leftmost bit the MSB.
In unsigned notation like this, there are a total of 2n combinations of the digits where n is the number of bits in a word. If there are 32 bits in a word, then 232 numbers can be represented. If we made a sequence of these numbers, it will start from 0, so the last number is exactly 1 less than the number of combinations, that is, 2n - 1. So, in unsigned notation, numbers [0, 2n - 1] are represented.
QUESTION 1 Represent the decimal number 254 in unsigned binary notation. What are the most and least significant bits?
ANSWER: The decimal number 254 is closest to a smaller (or equal) power of two, 128, or 27 . Divide 254 with that power. (Since the quotient is always 1, we replace the division by subtraction.) The remainder is 126. Do the same: The closest smaller (or equal) power of two is 64, or 26 . The difference is 62. With 25 = 32, the difference is 30. With 24 = 16, the difference is 14. With 23 = 8, the difference is 6. With 22 = 4, the difference is 2. With the equal power of two, 21 = 2, the difference is 0. The exponents of two are where the 1's are. They are bit positions 1, 2, 3, 4, 5, 6 and 7.
Let's use an octet (an eight-bit string). The leftmost is the MSB, so it is bit position 7. The rightmost is the LSB, and its bit position is 0. Now, arrange it:
1111 1110. This is our representation.
The MSB is 1, and the LSB is 0.
Let's use a 32-bit word. Again, the leftmost is the MSB, and its bit position is 31. The rightmost is the LSB, and its position is 0. Now, arrange it:
0000 0000 0000 0000 0000 0000 1111 1110. The MSB is changed: It is now 0. The LSB is still 0.
QUESTION 2 Represent 142 in unsigned representation.
Answer: Remember to choose the closest smaller (or equal) power of two, until the remainder (or difference) is 0. Then, record the bit positions---that's our method.
142 - 128 = 14
14 - 8 = 6
6 - 4 = 2
2 - 2 = 0
The powers are: 1, 2, 3, 7. Use an octet. The leftmost is the MSB, bit position 7, and the rightmost is the LSB, bit position 0. Arrange:
QUESTION 3 Decode
1001 1010 in unsigned rep. to decimal. The leftmost is the MSB.
Answer: It is a sum of powers of two. The 7th, 4th, 3rd and 1st powers are represented. So, add them up: 27 + 24 + 23 + 21 = 154.
Convert the positive integer 1,257,281 to binary:
- Is a byte sufficient to store the representation? A 2-byte word? A 32-bit word? A 64-bit word?
Consider the representation
1111 1111 in unsigned notation in a byte:
- What is its decimal value?
- If the most significant bit was assigned the value of -27 , instead of 27 ,then what is its new decimal value?