Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Binary number to a decimal equivalent

    Hello, I started java a few weeks ago for my programming class, and I got this assignment where I had to convert a binary number to an integer, or its decimal equivalent. We are not allowed to use shortcuts to convert a binary to a decimal, or import anything other than java.io.*; I know how the binary system works, but I just don't know how to implement it and make it into a program using java. Does anybody have any idea how I can approach this problem? Any help is appreciated thanks.

  • #2
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know the simple coding,

    import java.lang.*;
    import java.io.*;
    public class DecimalToBinary{
    public static void main(String args[]) throws IOException{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the decimal value:");
    String hex = bf.readLine();
    int i = Integer.parseInt(hex);
    String by = Integer.toBinaryString(i);
    System.out.println("Binary: " + by);
    }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •