Memory representation of signed int


Total size of unsigned int: 16 bit
Those eight bits are use as:
Data bit: 15
Signe bit: 1




Note: In c negative number is stored in 2’s complement format.

Example:
(1)Memory representation of:

signed int a=7;            (In Turbo c compiler)
signed short int a=7   (Both turbo c and Linux gcc compiler)
Binary equivalent of data 7 in 16 bit:  00000000 00000111
Data bit: 0000000 00000111 (Take first 15 bit form right side)
Sign bit: 0                 (Take leftmost one bit)

First eight bit of data bit from right side i.e. 00000111 will store in the leftmost byte from right to left side and rest seven bit of data bit i.e. 0000000 will store in rightmost byte from right to left side as shown in the following figure:   




(2)Memory representation of:
signed int a=-7;          (In Turbo c compiler)
signed short int a=-7 (Both turbo c and Linux gcc compiler)
Binary equivalent of data 7 in 16 bit:  00000000 00000111
Binary equivalent of data -7 will be its 2’s complement:
1’s complements of 00000000 00000111 is 11111111 11111000
2’s complement will be:




Binary equivalent of data -7 in 16 bit: 11111111 11111001
Data bit: 1111111 11111001 (Take first 15 bit form right side)
Sign bit: 1                 (Take leftmost one bit)
First eight bit of data bit from right side i.e. 00000111 will store in the leftmost byte from right to left side and rest seven bit of data bit i.e. 1111111 will store in rightmost byte from right to left side as shown in the following figure:   





Introduction
List of data types
Primitive data types in c
Modifiers of data types in c
List of modifiers in c
Default modifiers of data types in c
Default data of modifiers in c
Rules of using modifiers in c
Possibles modifiers of given data types in c
Size modifier in c
Size of data types in c
Sign modifier in c
Range of data types in c
Easy way to remember limit of data types in c
Const modifiers in c
Pointers modifier in c
Function modifier in c
Interrupt modifier in c
Volatile modifier in c
Fundamental data types in c
Memory representation of char in c
Memory representation of signed char in c
Memory representation of int in c
Memory representation of signed int in c
Memory representation of double in c

3 comments:

dinhpq said...

Thanks.

Anonymous said...

Why memory representation is 11111001 11111110 and not 11111001 11111111 ( i'm talking about the picture)

Anonymous said...

last picture