0

I am learning solidity. Public address is dervied from last 20 bytes of public key. I have read that address data type has 20 bytes size and in many programme I have seen that they are equated to an address like

address val = 0x9361005EA8041821edF4BeaF5B0518d9e75AeB13 ;

We have stored our address with 0x at the front which makes it of 42 hexadecimal digits i.e. 21 bytes , so how address data type can store beyond its limit ?

1
  • 0x is just a symbol used as prefix to denote hexadecimal numbers. It doesn't add bits to the number.
    – 0xSanson
    Nov 18, 2022 at 14:24

1 Answer 1

3

An address data type stores 20 bytes value that represents an Ethereum address. An Ethereum address is always represented in hexadecimal format and prefixed with 0x. Prefixing by 0x does increase the total byte to 21 bytes, but doesn't mean the original address data type can store beyond 20 bytes. It's like if a cup can hold a maximum capacity of 8 oz of water, but doesn't mean adding a cap to the cup will increase its maximum capacity to 10 oz (although the total weight might increase slightly). The cap is there so the water doesn't spill over (like how adding 0x to the prefix lets the receiver of the address know it's in hexadecimal format).

1
  • 1
    Excellent analogy!
    – Peter
    Feb 8, 2023 at 3:37

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.