CS 1711 Lab 8 - November 17 and 19, 1998

Lab tests next week: November 24 and 26!!

Storage of integers with binary digits

This lab involves conversion of an array of char to an array of integers with values limited to be 0 or 1. The array is going to be interpreted as a positive integer with binary digits as found in the array. Recall that any positive integer can be represented with place notation in any base, for example the the integer we write as 105 in decimal notation is actually

1 x b2 + 0 x b1 + 5 x b0

where b, the base is 10 in this case, and the coefficients of powers of b must come from a set of b symbols for digits: 0,1,2,...,b-1. We already considered b = 8 on an assignment. Here we will work with b = 2. What happens if b is greater than 10? In that case we need more symbols than the usual digits 0,1,...,9 so what is commonly done is to adopt the upper case Latin alphabet. An important case (Why?) is b = 16 = 24! where the digits are 0,1,...,9,A,...,F.

A collection of stub functions and a main driver program has been written for you. The function stubs are written just to let the program execute but not correctly. Your job is to `fill' in the missing statments; please follow the order below.

  1. Obtain the file from the directory for Lab 8 and carefully read the function prototypes.
  2. Write the function bin_2_int() which receives an array of integers consisting of 0's and 1's (and its size and number of elements used) and outputs the corresponding binary integer as a decimal integer. TEST this function. Note that in order to test the new function you can simply comment out the existing driver program.

    Write the inputs you used for testing at the bottom of this sheet to show to the lab instructor.

  3. Write and TEST the function print_bin() which displays the binary number stored in the array bin[] on the screen.
  4. Write and TEST the function int_2_bin() which accepts a decimal integer and returns a binary integer stored as an array.
  5. Write and TEST the function bin_2_int() which accepts a binary integer stored as an array and returns an decimal integer.
  6. Now modify the driver program so that it will accept a (decimal) integer N and (if possible) display the binary representation of integers from 1 to N.
  7. Demonstrate your completed program to the lab instructor and be prepared to explain the test values used.

Function print_bin Test Values:

Function int_2_bin Test Values:

Function bin_2_int Test Values: