Conteúdo do Curso
Introduction to Blockchain
Introduction to Blockchain
More About Block Header
Before we can proceed to exploring the block header in details, we should first understand the difference between big endian and little endian formats.
Little Endian and Big Endian
First, we have to understand what endianness actually means.
Big endian format stores the most significant byte first, which aligns with how humans typically read numbers. Let's use the decimal number 234567890
as an example and convert it to hexadecimal and binary using Python and output the results:
decimal_number = 234567890 print(hex(decimal_number)) print(bin(decimal_number))
Since computers store integers using a whole number of bytes, and each 2 hex digits correspond to one byte, we need an even number of digits. The hex representation of our number, 0xDFB38D2
, contains 7 digits, so we need to add zero 0
to the left. The resulting number, 0x0DFB38D2
, now has 8 hex digits (fits exactly 4 bytes) and the same value.
Similarly, our binary number has 28 bits, and every 8 bits correspond to 1 byte, so we need to the number of bits divisible by 8 adding 4 zeros 0
to the left. The resulting number, 0b00001101111110110011100011010010
, now has 32 bits (fits exactly 4 bytes) and the same value.
Using Python, we got the big endian format, which we would also get if we converted manually, and our number looks as follows:
0x0DFB38D2
in hex;0b00001101111110110011100011010010
in binary.
Let's take a look at the table below for to understand the big endian format:
Conversely, little endian format stores the least significant byte first, reversing the intuitive order:
As you can see, our number in little endian format looks as follows:
0xD238FB0D
in hex;0b11010010001110001111101100001101
in binary.
Back to Block Header
To recap, the header is exactly 80 bytes containing six data fields, each of them being in little endian format. Let's now take a look at the header of block 645536:
Since the block header takes up exactly 80 bytes, there are exactly 160 hex digits (each byte corresponds to 2 hex digits). The Version field, for example, takes up 4 bytes, so there are 8 hex digits.
Here is the detailed info about this block in the explorer:
The fields here are shown in big endian format. Let's inspect the Bits field, for example, and compare it with its representation in the block header. Its hex representation is 0x171007ea
in big endian format:
If we convert it to little endian format, it will look as follows:
As you can see, that's exactly what we had in the block header.
Obrigado pelo seu feedback!