Category Archives: Binary

How swab32 or bswap_32 works

By | February 15, 2016

If you have come across some code with reference to swab32 or bswap_32 and wondered how it works, here is the answer. swab32 will probably be a function that calls bswap_32 which will probably be a macro. The macro will probably be defined as: ( (((x) << 24) & 0xff000000u) | (((x) << 8) &… Read More »

Big Endian and Little Endian in Pictures

By | February 12, 2016

You may have come across this image on Wikipedia when reading about endianness. While it is great, in practice when I’m viewing content in memory, it is displayed horizontally instead of vertically. So for those visual people out there, here is another take.       Big endian is defined at placing the Most Significant… Read More »

How to calculate CRC32 by hand?

By | November 7, 2015

Introduction A 32 bit Cyclical Redundancy Check is a means of error detection in data transmission. There are plenty of online calculators that will help you automatically calculate the CRC32 of a given value. What I wanted to do was to understand how it is calculated. So what better way than to try and replicate a… Read More »

What does the bitcoin target really mean – part 2

By | April 8, 2015

I’ve done a lot of reading trying to figure out what a bitcoin target really means and after reading over 10 different explainations, over several days, I think I finally understand. Here are some of the basics. 1. You’ll see people talk about the maximum target of: 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF. What the heck does this mean and… Read More »

Real example of biased exponent of a number

By | April 6, 2015

After lots of Googling to try and understand what an exponent bias really means, I came across this video which explains it pretty well. When someone talks about biasing the exponent, it means trying to represent negative numbers with positive numbers so you don’t have to put a negative sign in front. It is just… Read More »

CPU Miner

By | March 3, 2015

It was a challenge dusting off my old C programming book and trying to recompile CPU miner from scratch on bare bones code and keeping just the essentials. It was hard work but it allows you to get a deeper understanding of what is really happening under the hood. Constructing the coinbase was the most… Read More »