Variables and Data types – Storage and size

In this lesson we discuss about the storage of variables in memory and the size of different data types.

Data is stored in binary format (0 or 1) and the basic unit of storage is Bit
Bits can be either 0 or 1
Data is stored in multiple bits
for example 4 bits can store maximum 1111 which is equivalent of 2^4 = 15
For data types which also store negative numbers the left most bit is used to store the sign and the remaining bits to store data.
So in case of 4 bits 3 bits will be used to data.
So the maximum value that can be stored is
0111 = 2^3 = 7
For representing negative numbers there are multiple methods the simple of which is one’s complement.
In ones complete a negative number will be represented by flipping all the bits of the equivalent positive number.
For example 7 is represented below
0111 = 7
To represent -7 we flip all 0 to 1 and 1 to 0
1000 = -7
Here the left most bit has value 1 which indicates this is a negative number.

Characters are represented in same format by converting to their ASCII values.