Java Program for Binary to Decimal Conversion | Study Table

 import java.util.Scanner;

public class BinaryToDecimal
{
    public static int dec, q, rem;
    public static StringBuffer sb;
    public static void main(String args[])
    {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a Decimal Value: ");
        dec = scanner.nextInt();
        sb = new StringBuffer(" ");
        q = dec; rem = 0;
        BinaryToDecimal object = new BinaryToDecimal();
        System.out.println("The Binary form is "+(object.Binary(dec)).reverse());
        scanner.close();
    }

    StringBuffer Binary(int dec)
    {
        dec = dec/2; rem = q%2;
        sb.append(Integer.toString(rem));
        q = dec;
        if(q>0) Binary(q);
        else return sb;
        return sb;
    }
}

Comments

Popular posts from this blog

Binary Search Program for Java | Study Table

[ ICSE ] Write a Letter to a Bookseller, complaining that the books supplied by him were not the latest Editions, though you have paid the money according to the latest Editions as given in the Bookseller's Catalogue. Request him to send you the latest Editions of the books and assure him that you would send back the old edition books supplied by him | Study Table