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!
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:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 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 =)