Tag Archives: ARM

What does endianness have to do with Bitcoins

The order of the byte appears is called the endianness in computer technology. This term stem from processor architecture design, for example, x86 and the classic 6502 is little endian, while S/360 and SPARC are big endian. ARM processors like the one powering the Beagleboard SBC I am happy with from Yubikey to the R statistics package can be configured to run either.

At the end of the day, programs are compiled and linked to instruction sets for the hardware processor to execute. But that is not the end of the story for software developers. Apart from the hardware instruction sets there are also endianness in file. Any developers having involved in any form of low level file processing, in classic or modern programming languages alike, should be very familiar with this.

Take the bitcoin file as en example, the hex dump below is the genesis bitcoin with the timestamp field highlighted in yellow.

bitcoinraw02

On file it reads 29AB5F49, but for the sake of endianness, this value should be interpreted as 495FAB29 in hexadecimal, and the corresponding decimal value is 1231006505. Converting this decimal value timestamp into human readable date:
bitcoinraw03

It is quite trivial to convert from one to another through programming languages and a classic C example as simple as the below macro will do the job.

bitcoinraw04

In Python:

bitcoinraw07

Advertisements