Skip to main content

Exercises 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).

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

    • \(\displaystyle F = 2 \times F\)

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

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

    • \(\displaystyle i = i - 1\)