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:


23 comments:

Muhammad Rafeeq C A said...

Very Good Explanation. Thank you.

Anonymous said...

thanks a lot

abhi01 said...

Thanks u very much...

Ravikant said...

gr888 work

mayank said...

good one :)

zaki said...

Really, very good explanation.....

gourab said...

nicely explained...thanks a lot...

Unknown said...

i understood very clearly..thanks a lot

Anonymous said...

really good explanation

Anonymous said...

good explaines.. thanks...

Anonymous said...

Thank U Very Much Sir.......

Dhanasree.D said...

very good site, helping me a lot, thank you very much.

azaruddin said...

that's what i m finding for,thanks a lot brother

Anonymous said...

fantastic explanation thnks....

Rahul Sarma. said...

I understand.
But if you can give me a vedio.

Anonymous said...

How to say Thanks I don't know . Wonderful...

Unknown said...

I appreciate your work but sorry to say where is the representation of integer data type and m not gtng ur explanation pls reply ADMIN.............. its a kind request ............ pls.......... if possible reply................

Unknown said...

I appreciate your work but sorry to say where is the representation of integer data type and m not gtng ur explanation pls reply ADMIN.............. its a kind request ............ pls.......... if possible reply................

1qubal said...

good one!!!thanx a lot...

Unknown said...

Very Nice :)

manohar said...

vry gooooooo

Unknown said...

thank you very much

Unknown said...

Really,This is best site for improving c language....