bits&bytes

“It is not about bits, bytes and protocols, but profits, losses and margins” Lou Gerstner

In computer in general we mentioned that the language of a computer is binary. There only two digits that constitutes the language. These two digits are 0 and 1.

For example if we want to say 75 in binary language, it would be: 01001011

At the bottom line, any program no-matter what language it is written, the program’s source-code and its data will be converted to binary because this is the only language computers understand.

The smallest unit of storage in a memory is called bit. We can think of a memory as millions of bits put together to create a large storage space.

Each bit is just a place holder that can only hold either a value 1 or 0.

For example if we want to store the number 75, first the number will be converted into its binary form which is 01001011 then 8 blocks of memory (8 bits) will be set aside for this value to be stored in.

Byte:

These days a computer needs to process huge amounts of data. Even a simple program can takes more than 100 of thousands up to millions of bits in memory.

Because programs started to take larger portion of memory space, other units of measurement was necessary to stop the pain of using large numbers in order to mention the amount of space a program might take in the memory.

Byte is another unit of measurement and is equal to 8 blocks of bits.

1 Byte = 8 Bits.

Then we’ve got other units of measurements like Kilobyte, Megabyte, Gigabyte, Terabyte etc.

In short:

1 Kilobyte = 1000 Bytes;

1 Megabyte = 1000 Kilobytes;

1 Gigabyte = 1000 Megabyte;

1 Terabyte = 1000 Gigabyte;

In data types section, we mentioned that a data like int will take 4 bytes of memory. Or the type long will take about 8 bytes of memory.

Note: the space a type like int takes in memory is system dependent. In one system it is 4 bytes, in the other might be equal to 8 bytes etc.!

Now we know if there’s a variable of type int for example, that variable might take 4 bytes (32 bits of the underlying memory).

Or if there’s a variable of type long, that variable might take 8 bytes (64 bits of the underlying memory).

This means a specific amount of memory is set aside for each variable of these types and any value that we assign to these variables will be stored in their related blocks of memory.

Now let's see how a value like a decimal number can be converted into binary and return back to decimal again:

Let’s say we have a variable named dec of type int:

int dec;

Let’s say the memory space for int type is 4 bytes. When this variable is declared, 4 bytes or 32 bits of memory will be set aside for it.

Make sure you first read the C++ prime plus page 69