🎛️Technical Basics
Last updated
Last updated
In Ethereum, and more broadly in the world of cryptography and blockchain technology, the prefix 0x
is used everywhere... but why?
The prefix 0x
indicates that the following string is in hexadecimal (base 16) format. Hexadecimal is a numeral system that uses 16 symbols: 0-9 to represent values 0 to 9 and A-F to represent values 10 to 15.
By starting with 0x
Ethereum ensures no ambiguity about the data format.
0x
means "The string that follows is a hexadecimal!"
For example, an Ethereum address looks like 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
and is represented in a hexadecimal format.
Type | Value |
---|---|
Hexadecimal |
|
Base 10 |
|
Base 2 (Binary) |
|
You'll notice from the table that the hexadecimal representation is the shortest number of characters.
Each hexadecimal digit represents four binary digits (bits).
This means a long binary string can be represented by a much shorter hexadecimal string, making it easier to read, write, and communicate.
A uint8
in Solidity is an unsigned integer that can hold values from 0 to 255.
It uses 8 bits (1 byte) to represent these values.
An 8-bit binary number can range from 00000000
(0) to 11111111
(255). For example, the number 150 in binary is 10010110
.
Group the 8 bits into two 4-bit groups (nibbles): 1001
and 0110
.
Convert to Hexadecimal:
1001
in binary is 9
in hexadecimal.
0110
in binary is 6
in hexadecimal.
Thus, the binary 10010110
becomes 0x96
in hexadecimal.
In Solidity, these are equivalent statements:
A uint256
variable can hold values from 0
to 2^256 - 1
.
Maximum uint256
value
Base 10: 115792089237316195423570985008687907853269984665640564039457584007913129639935
Hexadecimal: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
A 256-bit binary number can range from 00000000…00000000 (0) to 11111111…11111111 (2^256 - 1).
uint256
means it is an unsigned integer that uses 256 bits.
256 bits = 32 bytes (since 1 byte = 8 bits).