Ver Mensaje Individual
  #5  
Antiguo 02-09-2011
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola mightydragonlor.

Otra opción puede ser:
Código Delphi [-]
...
const
   B_BIN: array [0..15] of string= ('0000','0001','0010','0011','0100','0101','0110','0111',
                                    '1000','1001','1010','1011','1100','1101','1110','1111');
   B_HEX: array [0..15] of char=  ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');

function HexadecimalBinario(Value:string):string;
var
  i:integer;
begin
  for i:= 1 to Length(Value) do
    if not (Value[i] in ['0'..'9','A'..'F']) then
      raise Exception.Create('Número hexadecimal inválido');
  for i:= Length(Value) downto 1 do
    Result:= B_BIN[StrToInt('$'+Value[i])] + Result;
end;

function BinarioHexadecimal(Value:string):string;
var
  i,n:integer;
  Nbl:string;
begin
  for i:= 1 to Length(Value) do
    if not (Value[i] in ['0','1']) then
      raise Exception.Create('Número binario inválido');
  Value:= Value + Copy('000', 1, Length(Value) mod 4);
  for i:=0 to (Length(Value) shr 2)-1 do
  begin
    Nbl:= Copy(Value,(i shl 2)+1,4);
    n:= 8;
    while (Nbl<> B_BIN[n]) do
      if Nbl > B_BIN[n] then Inc(n) else Dec(n);
    Result:= Result + B_HEX[n];
  end;
end;
...

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 02-09-2011 a las 05:02:32.
Responder Con Cita