[Ethereum] what is the meaning of 0x0? say when variable gets assigned to it, example: keccak256(number) = 0x0;

remixsolidity

Is 0x0 just zero? thanks

keccak256(number) = 0x0; 

Or when not used as address I mean just to denote variable?

Best Answer

The 0x prefix means hexadecimal and it's a way to tell programs, contracts, APIs that the input should be interpreted as a hexadecimal number (we'll shorten to hex). 0x0 is actually 0 but in hex. Usually we use 0x0 to check whether the address is not set by us and it is set to default value by the solidity which is 0x0.

require(_addressIn != address(0))

E.g. 0x0 in Solidity is short for 0x0000000000000000000000000000000000000000, and if we use this as some address than it does have value greater than zero. check here.

Keccak256 computes the Ethereum-SHA-3 (Keccak-256) hash (doc) of the arguments passed into the function. So the above line of code is not correct because keccak256(number) is returning the hash value which you can store in some variable, instead you are trying to treat the output hash value as an variable and assigning the 0x0 to that.

I hope it helps.

Related Topic