Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Binary, Decimal, and Hexadecimal Numeral Systems | Blocks and Transactions
Introduction to Blockchain
course content

Conteúdo do Curso

Introduction to Blockchain

Introduction to Blockchain

1. Getting Started
2. Blocks and Transactions
3. Advanced Blockchain Concepts

bookBinary, Decimal, and Hexadecimal Numeral Systems

In the realm of blockchain and computing, understanding numeral systems is fundamental, mainly binary, decimal, and hexadecimal.

Decimal System

The decimal system, or base-10 system, is our everyday system of counting and uses ten digits, 0 through 9. While not used directly in the mechanics of the blockchain, it is the system we use to interpret values.

Binary System

The binary system, or base-2 system, is the core language of computers, representing values using two digits: 0 and 1. Each digit in binary is called a bit, the basic unit of information. Number 4 in binary, for instance, is 100.

However, in computer memory, the number of bits required for an integer has to be chosen in advance. Suppose we want 8 bits (1 byte) for an integer meaning that the integer must always take up eight digits regardless whether it uses all of them. Number 4 will be represented as follows: 00000100.

Let's take a look at the decimal numbers from 0 to 4 represented as 8-bit (1-byte) integers in binary:

Hexadecimal System

Hexadecimal system, or base-16 system, extends the decimal system to sixteen symbols: 0 to 9 followed by a to f (a = 10, b = 11, ..., f = 15). Moreover, hexadecimal numbers are often prefixed with the 0x characters. In computing, hexadecimal provides a more human-friendly representation of binary-coded values.

It's compact and easier to understand at a glance than binary, especially for large numbers. Bitcoin's block headers, for example, are stored in hexadecimal, however, processed in binary.

Let's extend the table above with hexadecimal representations of 1-byte integers from 0 to 15:

Similarly to hexadecimal numbers, binary numbers are also sometimes prefixed with the 0b characters.

Binary/Decimal Conversion

To convert binary to decimal, multiply each bit by 2 raised to the power of its position from right to left, starting with 0, and sum the results. Here is an example:

Binary: 1101
Decimal: 1*2^3 + 1*2^2 + 0*2^1 + 1*2^0 = 8 + 4 + 0 + 1 = 13

To convert decimal to binary, divide the number by 2 and write down the remainder. Continue dividing the quotient by 2 until you get a quotient of zero. The binary number is the remainders read in reverse order.

Let's take a look at an example:

Decimal: 13
Binary: 1101 (13 divided by 2 is 6 remainder 1, 6 divided by 2 is 3 remainder 0, 3 divided by 2 is 1 remainder 1, and 1 divided by 2 is 0 remainder 1)

Hexadecimal/Decimal Conversion

To convert hexadecimal to decimal, convert each hexadecimal digit to a decimal number and then, similarly to binary, multiply each converted digit by 16 raised to the power of its position from right to left, starting with 0, and sum the results.

Hexadecimal: 1A3
Decimal: 1*16^2 + 10*16^1 + 3*16^0 = 256 + 160 + 3 = 419

To convert decimal to hexadecimal, divide the number by 16 and write down the remainder. Continue dividing the quotient by 16 until you get a quotient of zero. The hexadecimal number is the remainders read in reverse order.

Decimal: 419
Hexadecimal: 1A3 (419 divided by 16 is 26 remainder 3, and 26 divided by 16 is 1 remainder 10, which is 'A' in hex)

Binary/Hexadecimal Conversion

In order to convert binary to hexadecimal or vice versa, you can first convert to decimal, then convert from decimal to the respective numeral system.

question-icon
Write down the correct representations of given numbers in different numeral systems. Do NOT use the 0x prefix for hexadecimal numbers and 0b prefix for decimal numbers.

25 (decimal) in binary:

382 (decimal) in hexadecimal:


110010 (binary) in decimal:


CA (hexadecimal) in decimal:

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 2
some-alt