//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//十进制转16进制
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int Dint;
Dint=StrToInt(Edit2->Text);
Edit3->Text=IntToHex(Dint,2);
}
//---------------------------------------------------------------------------
//十六进制转二进制
void __fastcall TForm1::Button3Click(TObject *Sender)
{
int i;
AnsiString BinaryTemp;
AnsiString BinaryStr;
char str[256];
memset(str,0,sizeof(str));
strcpy(str,Edit3->Text.c_str());
int L;
L=strlen(str);// .GetLength();
for(i=0;i<L;i++)
{
char temp[1];
memset(temp,0,sizeof(temp));
strncpy(temp,str+i,1);
if(temp[0]=='0')
BinaryTemp="0000" ;
else if(temp[0]=='1')
BinaryTemp="0001" ;
else if(temp[0]=='2')
BinaryTemp="0010" ;
else if(temp[0]=='3')
BinaryTemp="0011" ;
else if(temp[0]=='4')
BinaryTemp="0100" ;
else if(temp[0]=='5')
BinaryTemp="0101" ;
else if(temp[0]=='6')
BinaryTemp="0110" ;
else if(temp[0]=='7')
BinaryTemp="0111" ;
else if(temp[0]=='8')
BinaryTemp="1000" ;
else if(temp[0]=='9')
BinaryTemp="1001" ;
else if(temp[0]=='A')
BinaryTemp="1010" ;
else if(temp[0]=='B')
BinaryTemp="1011" ;
else if(temp[0]=='C')
BinaryTemp="1100" ;
else if(temp[0]=='D')
BinaryTemp="1101" ;
else if(temp[0]=='E')
BinaryTemp="1110" ;
else if(temp[0]=='F')
BinaryTemp="1111" ;
else
{
ShowMessage("不是十六进制");
return;
}
BinaryStr=BinaryStr + BinaryTemp;
}
Edit1->Text= BinaryStr;
}
//---------------------------------------------------------------------------