Sample Program:-
public class DecimalToBinary {
public static void main(String[] args) {
int decimal = 14;
if (decimal == 0) {
System.out.println("0");
}
String binary = "";
while (decimal > 0) {
binary = (decimal % 2) + binary;
decimal = decimal / 2;
}
System.out.println("Binary value is:" + binary);
}
}
Output:-
Binary value is:1110
Enjoy Coding.
No comments:
Post a Comment