Hi everyone! Can anyone tell me how the compiler cast an int to a char? I need this information for a assembly work.
Thanks any help!
This is a discussion on int to char within the C++ Programming forums, part of the General Programming Boards category; Hi everyone! Can anyone tell me how the compiler cast an int to a char? I need this information for ...
Hi everyone! Can anyone tell me how the compiler cast an int to a char? I need this information for a assembly work.
Thanks any help!
Nothing more to tell about me...
Happy day =)
If I understand your question correctly...
a char is just an 8-bit integer, because a char is just one of the 255 ASCII codes.
Same as the short datatype.
Code:int x = 5; char c = (char)x; //Here, x gets explicitly demoted to a char char d = x; //Here, x gets implicitly demoted to a char
Originally Posted by gustavosserra
Well, if you were working with a big-endian machine, just generate the appropriate 'mov byte' opcode, for little-endian, index the 4th byte of the integer (use that offset) in the opcode.
>> Same as the short datatype.
These days, shorts are typically 16 bits.
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
C++ cast:
Code:int Alpha = 35; char Beta = static_cast<char>(Alpha);
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
>> Can anyone tell me how the compiler cast an int to a char?
As Sebastiani posted, you'll want to write assembly that accomplishes the following:
ggCode:unsigned int I = 0xabcdef12; unsigned short S = I; unsigned char C = I; cout << hex; cout << "I = 0x" << I << endl; cout << "S = 0x" << S << endl; cout << "C = 0x" << (int)C << endl;
Assembly. Right! If you use VC++, write a program that does a c ast then add the /FA flag in the compilation options. This will produce a formatted assembly output file every time you compile. Then all you have to do is sniff out the part that does the casting.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Thanks everyone! Unfortunately I did not explain my problem well. I know how to tell the compiler to cast, but do not know how it implements. Thanks anyway =)
Sebastiani: thanks man! Iĺl do this way!
Nothing more to tell about me...
Happy day =)
I didn't see the later posts! Thanks Codeplug and Magos!!!
Nothing more to tell about me...
Happy day =)