[英]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();
i achieved to convert a hex string up to a certain size to an int. 我实现了将十六进制字符串转换为特定大小到int。
But when the string gets larger, then the int or long does not work, so i tried BigInteger. 但是当字符串变大时,int或long不起作用,所以我尝试了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 3个错误
You're trying to assign a primitive int value to a BigInteger reference variable. 您正在尝试将原始int值分配给BigInteger引用变量。 That won't work.
那不行。 You want to do
你想做
BigInteger hex = new BigInteger("45ffaaaaa", 16);
Also, you've named your class JEncrytion instead of JEncryption . 此外,您已将您的班级命名为JEncrytion而非JEncryption 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.