/Decimal To Binary

Decimal To Binary

Converting Decimal to Binary can be done from various ways , but lets check the easiest and the best way with minimum time complexity.

public class BinaryRepersentation {

    public static void main(String args[]) {
        int a = 43;
        String binary = tobinary(a);
        System.out.println(binary);
    }

    private static String tobinary(int a) {
        if(a==1)
        {
            return "1";
        }
        String s = "";
        int q = a / 2;
        int r = a % 2;
        s += tobinary(q);
        s+=r;
        return s;
    }
}