/*
 * The MIT License
 *
 * Copyright 2015 Sanket K.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package convert2bin;

import java.util.Arrays;

/**
 *
 * @author Sanket K
 */
public class Convert2bin {
    
    /*
    * Limitation: does not work for negatives yet
    * Does not scale easily for conversion to another base
    */
    public String simpleConvert(int input) {
        // Assume max size is 32
        int size = 32;
        int step = 1;
        int [] collector = new int[size];
        
        while (size > 0) {
            int t = ((input & step) != 0)?1:0;
            System.out.print(t + " ");
            step = step * 2;
            size--;
            collector[size] = t;
        }
        
        return Arrays.toString(collector);
    }
    
    public String divByX() {
        return null;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int a = -45;
        Convert2bin o = new Convert2bin();
        System.out.println("\nResult = " + o.simpleConvert(120));
        System.out.println("\nResult = " + o.simpleConvert(12));
        System.out.println("\nResult = " + o.simpleConvert(2220));     
        
    }    
}

@@ -1169,17 +1169,136 @@
 il.Array
-s
+List;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.concurrent.TimeUnit
 ;%0A%0A/**%0A 
@@ -1519,24 +1519,121 @@
 nt input) %7B%0A
+        if (input %3C 0) %7B%0A            return null;%0A        %7D%0A        long t1 = System.nanoTime();%0A
         // A
@@ -1954,32 +1954,108 @@
       %7D%0A        
+System.out.println(%22Done in %22 + (System.nanoTime() - t1) + %22 nano seconds%22);
 %0A        return 
@@ -2122,32 +2122,586 @@
 ByX(
-) %7B%0A        return null;
+int input, int radix) %7B%0A        if (input %3C 0) %7B%0A            return null;%0A        %7D%0A        long t1 = System.nanoTime();%0A        List collector = new ArrayList();%0A        int quotient = input;%0A        int remainder = 0;%0A        while (quotient %3E 0) %7B%0A            remainder = quotient %25 radix;%0A            quotient = quotient / radix;%0A            collector.add(remainder);%0A        %7D%0A        %0A        Collections.reverse(collector);%0A        System.out.println(%22Done in %22 + (System.nanoTime() - t1) + %22 nano seconds%22);%0A        return (Arrays.toString(collector.toArray()));        
 %0A   
@@ -2704,24 +2704,34 @@
 %0A    %7D%0A    %0A
+    %0A    %0A
     /**%0A    
@@ -2885,24 +2885,88 @@
 vert2bin();%0A
+        System.out.println(%22Method 1: brute force conversion%22);%0A
         Syst
@@ -3150,16 +3150,466 @@
 (2220));
+%0A        %0A        System.out.println(%22Method2: divide by radix%22);%0A        System.out.println(%22%5CnResult = %22 + o.divByX(120, 2));%0A        System.out.println(%22%5CnResult = %22 + o.divByX(12, 2));%0A        System.out.println(%22%5CnResult = %22 + o.divByX(2220, 2));%0A        %0A        System.out.println(%22%5CnResult = %22 + o.divByX(120, 3));%0A        System.out.println(%22%5CnResult = %22 + o.divByX(12, 3));%0A        System.out.println(%22%5CnResult = %22 + o.divByX(2220, 3));%0A   
      %0A  

add divide by radix method