chr*_*ris 3 java string android
今天早上简单,但导致我的问题,似乎无法找到任何代码.我创建了一个数字的十六进制表示,并希望现在保存十六进制字符串的最后4个字符,然后转换回整数.
转换的代码如下所示:
int in2 = new Integer(mycard.resourceid.toString());
String hex = Integer.toHexString(in2);
Run Code Online (Sandbox Code Playgroud)
如果有人能够朝着正确的方向推动我,我将非常感激.
int in3 = new Integer(hex.length());
int in4 = new Integer (in3 - 4);
String mystring = hex.subString(in4, in3);
Run Code Online (Sandbox Code Playgroud)
如果您只想轻推一下,请查找该类的substring方法String.
编辑:响应OP后续的一些示例代码:
public class Test {
public static void main(String[] args) throws Exception {
Integer in2 = 897387483;
String hex = Integer.toHexString(in2);
System.out.println(hex);
System.out.println(hex.substring(hex.length()-4, hex.length()));
}
}
Run Code Online (Sandbox Code Playgroud)