🎛️Technical Basics

Why 0x?

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.

Base 10:     0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal: 0 1 2 3 4 5 6 7 8 9 A  B  C  D  E  F

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.

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.

uint8 - Smallest Solidity Example

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:

uint8 public myNumberDecimal = 150;
uint8 public myNumberHex = 0x96;

uint256 - Biggest Solidity Example

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).

Last updated