Binary Fractions

Problem #93

Tags: computing

Who solved this?

Previous:Arbitrary Bases Next:Arbitrary Base Fractions


So far we have learned how to represent any integer for some arbitrary base b. But what about representing non-integer values, such as 1/2 or 3/8? At first the idea of representing a fractional value in binary may seem strange, but let's remind ourselves how we would represent these values using standard decimal notation.

So let's follow that same process to obtain the representation of 3/8 in binary.

Be sure not to refer to values to the right of a radix point as decimals when working in bases other than 10, as this will only cause widespread confusion and chaos.

Problem Statement

Input Data
First line will be Q, the quantity of testcases.
Q lines will follow, each containing two space-separated integers in the format X Y which describe some fraction X / Y.

Answer
Should consist of Q space-separated values corresponding to the binary representations of each given fraction.
Truncate all results to the first 10 digits following the radix point.

Example

input data:
5
1 2
3 8
2 3
83 89
89 13

answer:
0.1 0.011 0.1010101010 0.1110111010 110.1101100010
You need to login to get test data and submit solution.