问题
I have 4bytes of hex values directly without two's complement being applied to signed inetger. How do I get an int value from hex bytes using java.
回答1:
Doesn't this work?
int value = ((0xff & b4) < 24) | ((0xff & b3) < 16) | ((0xff & b2) < 8) | (0xff & b1);
回答2:
Use a Long. You can't use an int as it's always signed and 4 bytes just won't fit.
Long l = Long.parseLong("FFFFFFFF", 16);
来源:https://stackoverflow.com/questions/7662819/how-to-get-a-signed-32-bit-integer-from-hex-bytes-without-being-2s-complement-a