FaltuTech.Club : Fane of Advanced Logical Thriving Utopian Technical Club

Convert Decimal Number to Binary Using Java

Convert Decimal Number to Binary Using Java



class DeciToBinary{
    public static void main(String args[]){
        int a[]=new int[20];
	int toCon = Integer.parseInt(args[0]);
	int temp = toCon;
	for(int i=0;temp!=0;i++){
	
	a[i] = temp%2;
	temp = temp/2;

	}

	// reverse the array
		
	for(int i=0;i

Discussion

Above is long and tedious way to convert decimal to binary. Other way is :



class DeciToBinary{
    public static void main(String args[]){
	int toCon = Integer.parseInt(args[0]);
	String Con = Integer.toBinaryString(toCon);
	System.out.println("Binary is : " + Con);

	

	
    }
}