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?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityWhat'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?
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 :
"0x00000000000000000000000000000000000000000000000000000000075bcd15"