Memory Map of a Integer

How int data type is represented in the memory?
 

Ans:
 

int may be signed or unsigned both has different memory representation.
1. Memory representation of: unsigned int a=7;
It is 16-bit data type and all 16 bit is data bit.
Binary equivalent of 7 is 111
For 16 bit we will add 13 zero in the left side i.e 00000000 00000111
Since Turbo C is based on 8085 microprocessor which follow little-endian.
Here A is 00000111 and B is 00000000
Memory representation :

Note: same memory representation will be of : unsigned short int a=7;
2. Memory representation of: unsigned long int a=8888855555;
It is 32-bit data type and all 32 bit is data bit.
Binary equivalent of 888885555 is 110100 11111011 01010001 00110011
For 32 bit we will add 2 zero in the left side i.e 00110100 11111011 01010001 00110011
Here
A is 00110100
B is 11111011
C is 01010001
D is 00110011

Memory representation :

3.
(a) Memory representation of: int a=7 or signed int a=7;
It is 16 bit data type .
15 bit: data bit
1 bit: signed bit
Binary equivalent of 7 is 111
For 16 bit we will add 13 zero in the left side i.e 00000000 00000111
Here
A is 00000111
B is 00000000
Memory representation :

Note: same memory representation will be of: short int a=7 or signed short int a=7;


(b) Memory representation of : int a= -7 or signed int a= -7;
It is 16 bit data type .
Binary equivalent of 7 is 111
For 16 bit we will add 13 zero in the left side i.e 00000000 00000111
Since a is negative number so it will first convert in the 2’s complement format before stored in the memory.

Memory representation :

Note: same memory representation will be of : short int a=-7 or signed short int a=-7;

(4)
(a) Memory representation of :


long int a=8888855555 or signed long int a=8888855555;
It is 32 bit data type .
31 bit : data bit
1 bit : signed bit
Binary equivalent of 8888855555 is 110100 11111011 01010001 00110011
For 16 bit we will add 2 zero in the left side i.e 00110100 11111011 01010001 00110011
Here
A is 00110011
B is 01010001
C is 11111011
D is 00110100
Memory representation : 


(b) Memory representation of :
long int a= -8888855555 or signed long int a= -8888855555;
It is 32 bit data type .
Bit no 31 is signed bit.
Binary equivalent of 8888855555 is 110100 11111011 01010001 00110011
For 32 bit we will add 2 zero in the left side i.e 00110100 11111011 01010001 00110011
Since a is negative number so it will first convert in the 2’s complement format before stored in the memory.
Memory representation :

0 comments:

Post a Comment