PoiNtEr->: Memory Representation Of int data type in C Language

                             Difference between a dream and an aim. A dream requires soundless sleep, whereas an aim requires sleepless efforts.

Search This Blog

Wednesday, November 16, 2011

Memory Representation Of int data type in C Language


In computer science, an integer is a datum of integral data type, a data type which represents some finite subset

of the mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain

negative values.Int may be signed or unsigned both have different memory representation.numbers are represented in binary

only without extra symbols, requiring a method of encoding the minus sign. The four best-known methods of extending the binary

numeral system to represent signed numbers are: sign-and-magnitude, ones' complement, two's complement, and excess-K.
1. Memory representation of:

unsigned int a=7;


It is 16-bit data type and all 16 bits are data bit. Well we are here assuming that our microprocessor uses

little-endian method.So before moving any further first have a look on Endianness.


Memory representation:



 

23

Note: same memory representation will be of:

unsigned short int a=7;

 

 

 

 

 

2. 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:


signed p int

Note: same memory representation will be of:

short int a=7 or signed short int a=7;

 

 

 

 

 


3. 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.

1’s Complement of a: 11111111 11111000

+ 1

______________________

2’s Complement of a: 11111111 11111001


Memory representation:



signed n int

Note: same memory representation will be of:

short int a=-7 or signed short int a=-7


Reference:


1:http://cquestionbank.blogspot.com


2:http://c-pointer.blogspot.com


3:http://en.wikipedia.org/wiki/Signed_number_representations

No comments:

Post a Comment