Alan Bellingham
2008-05-25 18:21:02 UTC
"Your Name" <your-***@anywhere.net> wrote:
You may want to fill your name in, at least!
it's often not safe. In this case, you're trying to convert a pointer to
an unsigned char - and that makes no sense to the compiler. You had to
hit it over the head with the sledgehammer of a C-style cast to get it
to agree to do what you wanted.
Interestingly, 27338816 (decimal) is 0x1A12840. You've cast your pointer
to an unsigned char, which is one byte rather than 4, so it truncates
that value down to 0x40. Which, in decimal, is the 64 you're seeing.
So,
x2 = static_cast<unsigned char>(out[0]);
should do it (bearing in mind I never use AnsiStrings, so there might be
a typo in there.) The cast is there only because of the possible
signed/unsigned difference (you may have signed chars turned on).
Alan Bellingham
You may want to fill your name in, at least!
i have a typecast question, i need to get the decimal ascii-value
of a single char (0-127, in this case "E" should return 69)!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
unsigned int x2;
AnsiString out = "E";
x2 = (unsigned char)out.c_str();
Avoid using that type of C cast in C++. It's almost never necessary, andof a single char (0-127, in this case "E" should return 69)!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
unsigned int x2;
AnsiString out = "E";
x2 = (unsigned char)out.c_str();
it's often not safe. In this case, you're trying to convert a pointer to
an unsigned char - and that makes no sense to the compiler. You had to
hit it over the head with the sledgehammer of a C-style cast to get it
to agree to do what you wanted.
Interestingly, 27338816 (decimal) is 0x1A12840. You've cast your pointer
to an unsigned char, which is one byte rather than 4, so it truncates
that value down to 0x40. Which, in decimal, is the 64 you're seeing.
Edit2->Text = AnsiString(x2); // returns 64 however the input is
As just explained.x2 = (unsigned int)out.c_str();
Edit2->Text = AnsiString(x2); // returns 27338816
That's the full 0x1A12840 value.Edit2->Text = AnsiString(x2); // returns 27338816
}
How can i get the Ascii-Decimal(using BCB6 under Vista)?
You don't want the pointer, you want *what the pointer is pointing to*.How can i get the Ascii-Decimal(using BCB6 under Vista)?
So,
x2 = static_cast<unsigned char>(out[0]);
should do it (bearing in mind I never use AnsiStrings, so there might be
a typo in there.) The cast is there only because of the possible
signed/unsigned difference (you may have signed chars turned on).
Alan Bellingham
--
Team Browns
ACCU Conference 2009: to be announced
Team Browns
ACCU Conference 2009: to be announced