You are here:

C/Type Conversion

Advertisement


Question
Hello,

could u tell me how an integer type value convert into char type or the generalized question the Larger size data type value convert into smaller type data value....
I know various functions are available for this like- atoi, itoa.i used that function in program.
But i want to know how 2 bytes value accomodate in the 1 byte value...
explanantion by figure [ in bits and bytes ]would be more fruitful...

Regards
Ruchi

Answer
Hi Ruchi

Lets convert an integer to a char
int x = 3;
what gets stored inside this 2 bytes
000000000 00000011
now when we convert this to a char 1 byte what gets stored
the ascii value of 3 i.e. 51 which can be easily stored inside the 8 bits or 1 byte 00110011

I guess this example makes stuffs clear to you, but still in any case if you find any difficulty please lemme know so that I can come up with a more detailed explanation.

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.