# 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 be32enc and le32enc works in C

By | February 6, 2016

This is all about endianness. That is, how the bits are arranged in memory. You can arrange these bits in memory 2 ways. In big endian or in little endian. Go to wikipedia for some background but esssentially big endian is the way the decimal system works and little endian is the reverse of this.… 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 »

## Masking, bit-shifting and & 0xff00

By | April 29, 2015

If you are reading about endian (big and small) and seen snippets of code where you AND the input with 0xff00 and then shift the result say by 8 via >> 8 and wondering what the heck is going on then you’ve come to the right place. If you have an input such as int… 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 »