Skip to main content

Section 16.2 Programming Exercise

1.

Develop an algorithm to convert fractional decimal numbers to binary.

Hint

Multiply both sides of the fractional part of Equation (16.1.1) by \(2\text{.}\)

Solution

Refer to Equation (16.1.1).

  • \(i = -1\)
  • While (\(F \ne 0\)) AND (want-more-bits)

    • \(F = 2 \times F\)

    • \(d_{i} = int(F)\)

    • \(F = F - d_{i}\)

    • \(i = i - 1\)