// file:    toBinaryLSBF.java
// author:  Robert Keller
// purpose: convert a number to binary least-significant bit first

import intList.*;

class toBinaryLSBF
{

static intList toBinaryLSBF(int N)
  {
  if( N == 0 )
    return intList.cons(0, intList.nil);
  
  return toBinaryLSBFaux(N);
  }


static intList toBinaryLSBFaux(int N)
  {
  if( N == 0 )
    return intList.nil;

  return intList.cons(N%2, toBinaryLSBFaux(N/2));
  }

public static void main(String arg[])   // main program or test
  {
  intList.println(toBinaryLSBF(1042), System.out);
  }

}

