Solved

how to convert a binary to a decimal?

Posted on 2014-01-07
5
254 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
  • 3
  • 2
5 Comments
 

Author Comment

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

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 26

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now