Bit, Bytes and Hex

Everything are just zeros and ones?

Mopitz
3 min readJun 28, 2021
Photo by Markus Spiske on Unsplash

Context

Now that we are getting involve more and more with cryptocurrencies, we feel the necessity to go back to zeros and ones if we wan’t to develop or have a deep understanding in this subject.

Fundamental

We will start explaining that everything in programming comes from zeros and ones. So the minimal unit of computer is a bit.

A bit can represent the number zero or the number one bit(0 or 1), that’s it

But we can’t do that much with a single bit. In programming we need to be able to represent a bunch of numbers but how we can do it with a single tool(bit) that can be just a 0 or 1?

Here is where the byte comes into the game. A byte represent a group of 8 bits. So a byte could look like this:

00101101

So how can we represent different numbers with this group of bits? Simple, each combination of zeros and ones in that byte can represent a different number. Saying that the number of combination that we can represent in a byte are 255:

byte representation

With that formula, let show some example:

binary example
binary example
binary example
binary example
binary example

Great! so now we can understand how we can generate up to 255 numbers just using 1 single byte.

All the formula use the base 2 because we have just two options(1 and 0)

Programming

When we are programming specifically in cryptography, sometimes we want to represent bigger numbers like:

932423479237489237947328947923874892374982374872389472398345

But it is hard(why?) and liable to errors because of the big length of the number, so what if we can use the same logic of bytes but with a bigger base?

Here is where hexadecimal representation appears. Instead of having two option(0 and 1), we have 16 options!

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, a, b, c, d, e, f

Where a, b, c, d, e, f represent 10, 11, 12, 13, 14 and 15 respectively. This idea is to represent more options with a single character. So with the following formula we can represent any number in a shorter way.

hexadecimal formula

So the insane number mentioned before can be represented in hexadecimal like:

948B2B5A2AD713F5AA8FD7D312CBBF0329C1B96E2ADDF2AC09

Because of the big base that hexadecimal has, we can represent any byte with just 2 hexadecimals.

1 byte = 8 bits = 2 hex

Example:

155(decimal) = 10011011(binary) = 9B(hexadecimal)

--

--