android字符串转实数,Android签署int为无符号整数转换
我试图将带符号小数转换为无符号小数,但我不知道该怎么做。Android签署int为无符号整数转换
Android设备正在与另一个iOS设备通信,我们需要从一个平台向另一个平台发送颜色代码。由于这些平台具有不同的数据类型(Java签名数据类型和iOS无符号数据类型),因此我们需要进行转换才能在两边都具有相同的颜色。
这是我到目前为止做出:
// Parse and retrieve color code from the backend server
int unsignedColor = getColorFromBackend();
// Now add an alpha channel 'FF' and make it unsigned color
int signedColor = toSignedColor(unsignedColor);
// The signed value is -14701818
// Now try to make the conversion back, from signed to unsigned
int conversion = toUnsignedColor(signedColor);
// The value is: 129712 which is not the value I want (2075398)
private int toUnsignedColor(int signedColor) {
String hex = Integer.toHexString(signedColor);
hex = hex.substring(2, hex.length() - 1);
// hex = "1FAB06";
int unsignedInt = Integer.parseInt(hex, 16);
return unsignedInt;
}
private int toSignedColor(int unsignedColor) {
String hexColor = String.format("#%06X", (0xFFFFFFFF & unsignedColor));
// hexColor = "#FF1FAB06";
int signedColor = Color.parseColor(hexColor);
return signedColor;
}
// This is an example
private int getColorFromBackend() {
return 2075398;
}
+0
'试图将一个符号的十进制转换为一个无符号decimal'。你的意思是:有符号整数为无符号整数?请举个例子。并指出为什么会有问题。 –
+0
我不知道你是如何在Android和IOS之间发送数据的。因为你会发送四个字节在任何一个方向,我会想一个整数。无论是签名还是未签名。 –
+0
请举例说明从IOS接收有问题的数据。 –
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
