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:

unsignedinta=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:

Note:same memory representation will be of:

unsignedshortinta=7;

2. Memory representation of:

inta=7 orsignedinta=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:

shortinta=7 orsignedshortinta=7;

3. Memory representation of :

inta= -7 orsignedinta= -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:

Note:same memory representation will be of:

shortinta=-7 orsignedshortinta=-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