CS 2401 Assignment #4

Due Date: Monday, March 7 or Tuesday, March 8, depending on the day of your lab.

Objective: The goal of this assignment is to practice recursion.

Assignment: Write the following two methods:

  1. A method that transforms a non-negative decimal integer into a binary number -- i.e., into a string of 0s and 1s.
  2. A method that takes a string of 0s and 1s and transforms it into a decimal integer.

Details: The main ideas behind the corresponding recursive methods are similar to the ones described in Section 7.3.1 of the textbook.

The following algorithm translates the number n into a string of 0s and 1s:

For example, to transform the number 13 into the binary code: As a result, the number 1310 is converted into a binary string 11012.

The following algorithm converts a binary string to a decimal integer:

For example, to transform the string 1101 into an integer: