Showing posts with label decimal. Show all posts
Showing posts with label decimal. Show all posts

Monday, March 23, 2009

GATE 2002 CS question 1.14 (Number systems)

1.14 The decimal value of 0.25
(a) is equivalent to the binary value 0.1
(b) is equivalent to the binary value 0.01
(c) is equivalent to the binary value 0.00111...
(d) cannot be represented precisely in binary
This question must take only half a second if you know how to approach it.
The usual way of converting a decimal fraction to a binary one is to multiply it by 2, take the integer part, rinse and repeat.

Well, here we are not going to use that. Instead, we're going to be clever and use the meaning of number systems.
What is the value of 10 binary? It is 1 * 2^1 + 0 * 2^0. That is, we use decreasing powers of 2 as we move right.

Now, what is 0.1 binary? It is 1 * 2^(-1) which is 1/2. Similarly, 0.01 is 1 * 2^(-2) = 1/4 = 0.25.

Hey, haven't we arrived at the answer then? If 0.01 binary is 0.25 decimal, the answer we need is 0.01.

Yes, but there's something more we can learn here: if you manage to write any fractional value as the sum of 1/(powers of 2), you can directly write down its binary value. In some cases this might prove to save a lot of time. For example, if you asked to find the binary value of say 0.375, we see that it can be written as 0.25 + 0.125, so the answer is 0.011.

In this case, no such splitting was necessary. So, the answer to this question is: (b) is equivalent to the binary value 0.01