Binary 101: Saving the data.

In this post I will explain to you how your computer stores the binary data on your hard-drive.

Before we start you should know that there are two ways of saving the data. You can save your data in Little Endian or Big Endian. The difference between them is the way that the bytes are ordered. In my previous posts I’ve explained everything about binary in Little Endian. You can easily convert this to Big Endian by reversing the bytes.

When you store data on an hard-drive you always store it as a Byte. Each byte consists of 8 bits. By bundling multiple bytes together you can create higher values up to 64 bits (which explains why there are 32bit CPU’s and 64bit CPU’s). Here is a table of values that you can store on an hard-drive.

Name Amount of bytes used Amount of bits used Signed maximum value Unsigned maximum value
Byte 1 8 128 256
Short 2 16 32,767 65,535
Int 4 32 2,147,483,647 4,294,967,295
Long 8 64 18,446,744,073,709,551,616 9,223,372,036,854,775,807

The Signed maximum value is around the half of it’s unsigned maximum value. The reason for this is that unsigned values cannot be negative but signed values can even though they carry the same data.

The reason why there are multiple ways to store your data is that when you only need to save a number like 2,483 you don’t want to waste 32 bits of unused data. You do however have to make sure that when you read your data you read the correct type of data. When you save two Bytes but read them as a Short you will get a totally different value which is most likely invalid for your purpose.

In my table up above I’ve left out two important values that you can store on your hard-drive. These values are called floating point values. They have a special encoding (IEEE-754) since they are nowhere near normal values.

Type Sign Exponent Significant Total bits
Single 1 8 23 32
Double 1 11 52 64

When the sign bit is 1 it means that the value is a negative value. The significant is just a plain binary value. the exponent decides where the decimal should be and is always a negative value. If the value of the significant is 12345 and the value of the exponent is -3 and our sign bit is 0 it means that this value is 12.345

I hope that you’ve found my previous posts on Binary useful.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>