

The majority of the fields in transaction data are in little-endian format. It may not be the most user-friendly (or popular 1) choice, but modern computers almost always use the little-endian format internally, so this decision is a way of improving speed. Swap Endian - a basic tool that converts between little-endian and big-endian format (and vice-versa).īecause that’s the way bitcoin was designed. Whilst it does the job, it’s a superficial way of doing it, and does not benefit your understanding of what’s actually going on with the data. This is just a quick way of getting a string in to little-endian. Swap each pair of characters (starting from the right)… 21436587 If I want to quickly convert a string of data in to little-endian, I just swap each pair of characters (working from right-to-left), then reverse the string. So the little end is still first, but you’re taking 1 byte of that little-end at a time (and not simply 1 character at a time). So as you’re reversing the data in to being little-end first, you actually do it 1 byte at a time:Īnd so by reversing 2 characters (1 byte) at a time, we get 12345678 in little-endian: 78563412 Now, 1 byte is just some space in a computer’s memory, and holds 2 hexadecimal characters. Or to be more precise, they process data in “bytes”.

And that’s why many computer processors read data the “little-endian” way.īut wait, this still isn’t the same format as the actual little-endian number from the start… Bytes.Ĭomputers read through data in chunks. Sure, it’s a complete shift in the way you’re used to reading numbers, but if you’re a computer, this is arguably a much more logical way to do it. In this format, you’re working your way up from the least-significant value and finishing with the most-significant value. So as you’re processing this number in your head, you could say you’re starting with the big-end first.īut if you think about it, it could make just as much sense to start with the little-end first. When you read it from left to right, you start with the most-significant value first (i.e starting with 10000000 and ending with 8). Let’s look at that first number again: 12345678 “Little-endian” refers to the order in which bytes of information can be processed by a computer.įor example, here’s a hexadecimal number: 12345678Īnd here’s that same number in little-endian: 78563412Ī computer processor will read this number in the same way that we read it as 12345678… it’s just two different ways of reading the same thing.īitcoin likes using little-endian format for some data, so when working with code, you often have to get things in to little-endian format for them to work. The order of bytes that a computer likes to read in.
