What's the difference, in terms of bit structure, between an int and a uint under the EVM?

For an example, if an int8's value, expressed in binary, was 00010011, what would the uint8 of that be? What would negative 00010011 look like?


1 Answer 1


Edition (Thanks Tjaden): when an int is negative it is represented using two's complement system in which we get for an int: 1111 1111=−1(255 for uint) whereas 0000 0001=1 (1 for uint).

For example:

uint256 u=123456789;

is represented by 0x00000000000000000000000000000000000000000000000000000000075bcd15 ( Big Endian)

and int v=-123456789; is represented by 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffff8a432eb ( Big Endian )

int w=123456789

is represented by :

  • 5
    This is not entirely correct. Solidity (and the signed EVM opcodes) expect signed integers to be in two's complement form. You can't just flip the highest bit and make the number negative Commented Jul 19, 2017 at 10:24
  • Elaborating on @TjadenHess, you could use the signextend opCode to do this for you. Commented Jun 4, 2019 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.