Decimal to Binary Converter in Java (Console Based)

Submitted by: 
Language: 
Visitors have accessed this post 6961 times.

Today, we will try to create a Java program that enables the user input a DECIMAL number then it will convert to its BINARY equivalent value. If you remember, I posted a tutorial about a Java program that converts a decimal number to its octal value (you can read here). There are lot of sites from the Internet that you can download the program source code but in this tutorial, I made my own code which is based from the rules in number system conversion.

To do this, we will again follow the rules in converting. Here are the rules in converting decimal to binary:

1. Get or write the whole decimal number and serve as the dividend.

2. Use the base of the Binary, which is 2 as the divisor.

3. Proceed to Division operation.

4. The quotient and the remainder will be written on the other side whether 0 or 1. If the quotient is a whole number, the write 0 in the remainder, else if the quotient is a decimal number, then write 1.

5. Get again the quotient and divide into its base, repeat step # 4.

6. Repeat step # 5 until the quotient will be zero.

7. Write the remainder from bottom to up, to form the binary equivalent.

Download the free source code of the program below. Try now and leave some comments...Happy coding guys!

You can visit by site at www.eturo.co.cc


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.