简体   繁体   中英

Big Integer and Hex Strings in java

I am trying to convert a hex string to a decimal value (integer). Having found

int i = Integer.valueOf(s, 16).intValue();

here ,

i achieved to convert a hex string up to a certain size to an int.

But when the string gets larger, then the int or long does not work, so i tried BigInteger.

Unfortunately, it returns an error :

JEncrytion.java:186: <identifier> expected
                        BigInteger part_user_hex = Integer.valueOf("45ffaaaaa", 16).int();


JEncrytion.java:186: illegal start of expression
                        BigInteger part_user_hex = Integer.valueOf("45ffaaaaa", 16).int();


JEncrytion.java:186: not a statement
                        BigInteger part_user_hex = Integer.valueOf("45ffaaaaa", 16).int();

The code fragment is :

String[] parts = final_key.split("@") ;

String part_fixed = parts[0]; 

String part_user = parts[1]; 

BigInteger part_user_hex = Integer.valueOf("45ffaaaaa", 16).int();

System.out.println(""); 

System.out.println("hex value of the key : " + part_user_hex);  

Any ideas what to do?

3 errors

You're trying to assign a primitive int value to a BigInteger reference variable. That won't work. You want to do

BigInteger hex = new BigInteger("45ffaaaaa", 16);

Also, you've named your class JEncrytion instead of JEncryption .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM