Given the following string:
3132333435363738396162636465666768696a6b6c6d6e6f70
I converted the string to hex and now i want to file write it as hex not a string. I tried converting it to int but Integer.parseInt
converts up to 4 only and if go beyond that it would give error already.
BigInteger; public class Test { public static void main(String[] args) { String hex = "3132333435363738396162636465666768696a6b6c6d6e6f70"; BigInteger number = new BigInteger(hex , 16); System. out. println(number); // As decimal... } }
You convert a string to a number by calling the Parse or TryParse method found on numeric types ( int , long , double , and so on), or by using methods in the System. Convert class.
We can convert String to an int in java using Integer. parseInt() method. To convert String into Integer, we can use Integer. valueOf() method which returns instance of Integer class.
The method generally used to convert String to Integer in Java is parseInt() of String class.
Have you tried the BigInteger
constructor taking a string and a radix?
BigInteger value = new BigInteger(hex, 16);
Sample code:
import java.math.BigInteger;
public class Test {
public static void main(String[] args) {
String hex = "3132333435363738396162636465666768696a6b6c6d6e6f70";
BigInteger number = new BigInteger(hex , 16);
System.out.println(number); // As decimal...
}
}
Output:
308808885829455478403317837970537433512288994552567292653424
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With