Public paste
By: asdf | Date: Nov 24 2007 21:53 | Format: None | Expires: never | Size: 1.51 KB | Hits: 1179

  1. Your program will perform conversion from decimal representation to twos complement binary representation of integers, using recursive control.  Your program needs to:
  2. 1.      Read in an integer value from a file named input6.txt.
  3. 2.      Convert the input decimal value to twos complement. Note: The first entry in input6.txt specifies the minimum number of bits to be used to display the number in twos complement notation.
  4. 3.      Output to output6.txt the original decimal value and its twos complement form using at least n bits for the length of the binary.
  5.         These steps must be repeated as long as there are decimal numbers in the input file.
  7.         You must develop the algorithm first and then implement it. Use pseudocode for representing the algorithm. The algorithm must be detailed up to a level that shows the control structures (if, if-else, while, etc) needed.
  8.         Function main() must call function string convert(int decimal, int n) that receives the number and returns a string that represents the corresponding binary number in n bits format, where n is the minimum number of bits used to display the binary number.  
  9.         Function convert() will have to call the recursive function string dectobin(int decimal) that receives the decimal number and returns a string that represents the corresponding binary number in free format (that is, with just as many bits as needed to represent the value). Thus, it is the task of convert() to add the 0s (or 1s) to the string returned by dectobin() so that the binary number is in n bits format.