Java Program to convert binary to decimal – Q17
Q17: Java Program to convert binary to decimal
import javax.swing.*; class bin_dec{ public static void main(String args[]){ int bin, dec, i, x; String inp; //bin = Integer.parseInt(args[0]); inp = JOptionPane.showInputDialog("Enter a Binary Number:"); bin = Integer.parseInt(inp); i=0; dec = 0; while(bin != 0){ x = bin % 10; dec += x * Math.pow(2,i); bin /= 10; i++; } System.out.println("Decimal: " + dec); } }
… from College notes (BCA/MCA assignments):
Categories: Java
Binary to Decimal, Java Basic Programs
Comments (0)
Trackbacks (0)
Leave a comment
Trackback