I'm trying to parse a binary file in the browser. I have 4 bytes that represent a 32-bit signed integer.
Is there a straight forward way of converting this to a dart int, or do I have to calculate the inverse of two's complement manually?
Thanks
Edit: Using this for manually converting:
int readSignedInt() {
int value = readUnsignedInt();
if ((value & 0x80000000) > 0) {
// This is a negative number. Invert the bits and add 1
value = (~value & 0xFFFFFFFF) + 1;
// Add a negative sign
value = -value;
}
return value;
}