## INDEX

### Memory representation of char data type in C

Char data types may be signed or unsigned. Size of char data type is 8 bit. Both signed and unsigned have different memory representation.

Memory representation of unsigned char: In unsigned char all 8 bit is used as data bit

Memory representation of
unsigned char a= 7;
Binary equivalent of 7 is:  111
For 8 bit we will add 5 zero in the left side i.e. 00000111. In the memory:

Here MSD stand for most significant digit and LSD list significant digit.

Memory representation of signed char:

1 bit: signed bit
7 bit: data bit

Note: In C, negative number is stored in the 2’s complement format.

Signed bit is 0: Number is positive.
Signed bit is 1: Number is negative.

Memory representation of
char a=7;
Binary equivalent of 7 is: 111

For 8 bit we will add 5 zero in the left side i.e. 00000111. Memory representation:

Memory representation of char a=-7;

Binary equivalent of 7 is 111

For 8 bit we will add 5 zero in the left side i.e. 00000111. Since a is negative number so it will store in the memory in the 2’s complement format

1’s complement of a: 11111000
+      1
____________
2’s complement of a: 11111001

Memory representation:

Post a Comment