怎么将Edit1->Text中的16进制字符串转成2进制并显示在Edit2->Text中?
怎么将Edit1->Text中的16进制字符串转成2进制并显示在Edit2->Text中?
[解决办法]
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char pStr[8];
int Value = StrToInt(Edit1->Text);
itoa(Value,pStr,2);
Edit1->Text = pStr;
}
AnsiString h2b(AnsiString strHex)
{
AnsiString str;
strHex = strHex.UpperCase();
for (int i = 0; i < strHex.Length(); i++)
{
switch (strHex[i + 1])
{
case '0': str += "0000"; break;
case '1': str += "0001"; break;
case '2': str += "0010"; break;
case '3': str += "0011"; break;
case '4': str += "0100"; break;
case '5': str += "0101"; break;
case '6': str += "0110"; break;
case '7': str += "0111"; break;
case '8': str += "1000"; break;
case '9': str += "1001"; break;
case 'A': str += "1010"; break;
case 'B': str += "1011"; break;
case 'C': str += "1100"; break;
case 'D': str += "1101"; break;
case 'E': str += "1110"; break;
case 'F': str += "1111"; break;
default: break;
}
}
return str;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Edit2->Text = h2b(Edit1->Text);
}