Solved

how to convert a binary to a decimal?

Posted on 2014-01-07
5
269 Views
Last Modified: 2014-01-09
Given one string consisting of numbers which actually corresponds to a real big binary number(>0), how to convert it to a decimal string in java. For example,

"10010001000111110110110100010100001001100100101001010001100000011101111110011101000101101111101001101101111100110001100011001001101001" in binary =
"12345678910111213141516171819202122232425" in decimal
0
Comment
Question by:jl66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:jl66
ID: 39763488
Revised title.
0
 
LVL 27

Accepted Solution

by:
dpearson earned 500 total points
ID: 39764271
Check out the BigInteger class:
http://docs.oracle.com/javase/6/docs/api/java/math/BigInteger.html

One of the constructors takes a string and a "radix" which is the fancy term for base, so for binary this is 2:

            BigInteger bi = new BigInteger("100101000111111110000", 2);
                bi.toString() ; // Print it in Decimal

Hope that helps,

Doug
0
 

Author Comment

by:jl66
ID: 39764277
If we restrict the binary number to be <=2^128, is it a bit easy to resolve it?
0
 
LVL 27

Assisted Solution

by:dpearson
dpearson earned 500 total points
ID: 39764289
BigInteger handles arbitrary sized numbers.  So you should be fine with any sized binary.
0
 

Author Closing Comment

by:jl66
ID: 39769674
Thanks a lot. Very helpful.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to determine if a string is a valid SHA value 7 57
mysql jsp example issue 32 96
How to configure empty element in XML Document parser? 15 58
Java array sort 10 63
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question