Decimal to binary converter
Below is example java program decimal to binary converter which will convert any decimal number to its binary form and shows output on the console.
package com.javahonk.shiftoperator; public class DecimalToBinaryConvert { public static void main(String[] args) { System.out.println(decimalToBinary(46)); } private static Object decimalToBinary(int decimalNumber) { int remainderNumber; if (decimalNumber <= 1) { System.out.print(decimalNumber); return ""; } remainderNumber = decimalNumber % 2; decimalToBinary(decimalNumber >> 1); System.out.print(remainderNumber); { return ""; } } }
Output:
That’s it for Decimal to binary converter in java.