Hola.
Como para que uses de guía, te hice un ejemplo que pasa un numero hexadecimal a binario lo almacena en un
TRichEdit y pinta de colores los dígitos:
Código PHP:
String hexToBin(String value)
{
String BIN[16] = {"0000","0001","0010","0011","0100",
"0101","0110","0111","1000","1001",
"1010","1011","1100","1101","1110","1111"};
int i = 1;
String r;
while(i < value.Length())
{
char ch = toupper(value[i]);
if (ch >= '0' && ch <= '9')
r += BIN[ch - '0'];
else if (ch >= 'A' && ch <= 'F')
r += BIN[ch - 'A' + 10];
else
throw ("Caracter ilegal.");
i++;
;
}
return r;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TColor colors[8] = {clRed,clYellow,clBlue,clGreen,clBlack,
clLime,clRed,clLime};
RichEdit1->Text = hexToBin("2C8");
for(int i = 0; i < 8; i++)
{
RichEdit1->SelStart = i;
RichEdit1->SelLength = 1;
RichEdit1->SelAttributes->Color = colors[i];
}
}
Resultado:
Saludos
