Ver Mensaje Individual
  #5  
Antiguo 25-10-2008
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Creo que ya hay una función para convertir de binario a hexadecimal, pero tardo mas en buscarla que en hacerla
Código Delphi [-]
function BinToHex(Hex: String): String;
var
  i,j: Integer;
  Str: String;
begin
  Result:= EmptyStr;
  for i:= Length(Hex)  downto 1 do
    if not (Hex[i] in ['0','1']) then
      Delete(Hex,i,1);
  while Length(Hex) mod 4 <> 0 do
     Hex:= '0' + Hex;
  while Length(Hex) > 0 do
  begin
    Str:= Copy(Hex,1,4);
    Delete(Hex,1,4);
    j:= 0;
    for i:= 1 to Length(Str) do
      j:= (j * 2) + StrToInt(Str[i]);
    Result:= Result + IntToHex(j,1);
  end;
end;
Por ejemplo si tenemos varios edit, por ejemplo edit0..7, con los bits y uno, llamemosle edit8, donde queremos poner el resultado:
Código Delphi [-]
  Edit8.Text:= BinToHex(Edit0.Text + Edit1.Text + Edit2.Text + Edit3.Text +
    Edit4.Text + Edit5.Text + Edit6.Text + Edit7.Text)
Edit0 tendria el bit mas significativo y el Edit7 el menos
Responder Con Cita