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

Community
  • 1
  • 1
kiko77
  • 7
  • 7
  • possible duplicate of [Java convert a HEX String to a BigInt](http://stackoverflow.com/questions/4316645/java-convert-a-hex-string-to-a-bigint) – thegrinner Sep 25 '13 at 12:08
  • yes, it was perfect...just looking in another direction/ with other keywords. Thanx! – kiko77 Sep 25 '13 at 12:29

1 Answers1

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.

Kayaman
  • 72,141
  • 5
  • 83
  • 121