Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to convert a binary to a decimal?

Posted on 2014-01-07
5
Medium Priority
?
271 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 28

Accepted Solution

by:
dpearson earned 2000 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 28

Assisted Solution

by:dpearson
dpearson earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

671 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