|
Remy Lebeau (TeamB)님이 답변해주신 자료의 일부입니다.
테스트는 안해 봤다는 군요....
[첨부자료] newsgroups.borland.com의 borland.public.cppbuilder.students ------------
You'll have to convert it manually, for example (untested):
bool __fastcall HexToBinary(AnsiString Hex, AnsiString &Binary)
{
static char* HexBinaryLookup[] = {"0000", "0001", "0010", "0011",
"0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011",
"1100", "1101", "1110", "1111"};
Binary = "";
if( Hex.SubString(1, 2).AnsiCompareIC("0x") == 0 )
Hex.Delete(1, 2);
for(int i = 1; i <= Hex.Length(); ++i)
{
char c = Hex[i] & ~20; // simple way to force uppercase
int index = -1;
if( (c >= '0') && (c <= '9') )
index = (c - '0');
else if( (c >= 'A') && (c <= 'F' ) )
index = (c - 'A' + 10);
else
return false; // invalid input
Binary += HexBinaryLookup[index];
}
return !Binary.IsEmpty();
}
Then you can do something like this:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString binary;
if( HexToBinary(Edit1->Text, binary) )
Edit2->Text = binary;
else
ShowMessage("Please enter a valid hex value!");
}
Gambit
---------------------------------------------------------
|