Android:如何获取整数的十六进制偏移量

时间:2017-10-10 10:20:36

标签: android hex offset type-conversion

有没有办法获得整数的2个偏移量?

例如,如果我有:

int a= 5;
int b= 300;

我需要一种方法来获得这两个数字的十六进制偏移量:

String offseta_1 = "00";
String offseta_2 = "05";
String offsetb_1 = "01";
String offsetb_2 = "2c";

int offseta_1_int = 0;
int offseta_2_int = 5;
int offsetb_1_int = 1;
int offsetb_2 = 44;

如何在android中完成这个?

1 个答案:

答案 0 :(得分:0)

将DEC-INTEGER转换为HEX-STRING:

int i = 55;
String hexString = Integer.toHexString(i);  // = "0x37" OR "37"

将HEX-STRING转换为DEC-INTEGER:

// can be lower- and uppercase
// "0x" is optional, but hex-numbers should be marked like this
String hexString = "0xAF";
int decimalInt = Integer.parseInt(hexNumber, 16);  // = 175