0

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

2
  • possible duplicate of Java convert a HEX String to a BigInt Commented Sep 25, 2013 at 12:08
  • yes, it was perfect...just looking in another direction/ with other keywords. Thanx! Commented Sep 25, 2013 at 12:29

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.