我测试过ByteBuffer方法,即使参数一致,但是结果并不一致,求解决方法
python:
import struct
def account_id_to_steam_id(account_id: str) -> str:
first_bytes = int(account_id).to_bytes(4, byteorder="big")
print(first_bytes)
last_bytes = 0x1100001.to_bytes(4, byteorder="big")
print(first_bytes + last_bytes)
print(struct.unpack(">Q", last_bytes + first_bytes))
return str(struct.unpack(">Q", last_bytes + first_bytes)[0])
print(account_id_to_steam_id(account_id="1421145735"))
结果: 76561199381411463
java:
public static byte[] intToByte4(int i) {
byte[] targets = new byte[4];
targets[3] = (byte) (i & 0xFF);
targets[2] = (byte) (i >> 8 & 0xFF);
targets[1] = (byte) (i >> 16 & 0xFF);
targets[0] = (byte) (i >> 24 & 0xFF);
return targets;
}
main:
var b1 = NumberUtil.intToByte4(1421145735);
var b2 = NumberUtil.intToByte4(17825793);
byte[] result = Arrays.copyOf(b1, b1.length + b2.length);
System.arraycopy(b2, 0, result, b1.length, b2.length);
var buffer = ByteBuffer.wrap(result ) //
.order(java.nio.ByteOrder.LITTLE_ENDIAN)
System.out.println(buffer.getLong());
结果: 72075192800031828