C/C

Advertisement


Question
char has a range -128 to 127. it can be stored in 1 Bit= 8 bytes how can we store -128 into 8 bytes

Answer
hi Gandhi

check out this code
void main()
{
char c;
c = -128;
printf("%c",c);
}
this is how you store -128 into a char variable of 8 bits
where 7 bits are used for storing the number and the last bit is used as flag to identify whether the number is possitive or negative, and that is the reason why the range of variable gets increased when its is declared as unsigned where all the bits are used for storing the number.

regards
Joydeep Bhattacharya
http://www.scodz.com

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

Ability to solve C and Data Structure problems and puzzles with simple and easy to understand logic.

Experience

C, C++, Java, Data Structure, PHP, Web Designing

Organizations
http://www.scodz.com Designation: webmaster

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Past/Present Clients
http://analysingc.50webs.com http://www.funforu.com

©2012 About.com, a part of The New York Times Company. All rights reserved.