Thema: Delphi Binären Wert schreiben

Einzelnen Beitrag anzeigen

scp

Registriert seit: 31. Okt 2003
1.120 Beiträge
 
Delphi 7 Personal
 
#6

Re: Binären Wert schreiben

  Alt 1. Nov 2003, 17:56
Dann probiers mal hiermit:
Delphi-Quellcode:
function HexToBinStr(HexStr : string) : String;
const
  ValidHexChars : set Of Char = ['0'..'9', 'A'..'F', 'a'..'f'];
  Convert: array['0'..'f'] of SmallInt =
    ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
     -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
     -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
     -1,10,11,12,13,14,15);
var
  HexTmpStr : String;
  HexSize : Integer;
  HexPos : Integer;
begin
  result := '';
  HexTmpStr := HexStr + ' ';
  HexSize := length(HexTmpStr);
  HexPos := 0;
  while ((HexSize - HexPos) > 1) do
    begin
      while not (HexTmpStr[HexPos+1] in ValidHexChars) do
        begin
          Inc(HexPos);
          If ((HexSize - HexPos) < 1) then
            Break;
        end;
      If ((HexSize - HexPos) < 2) then
        Break;

      result := result + Char((Convert[HexTmpStr[HexPos+1]] shl 4) + Convert[HexTmpStr[HexPos+2]]);
      Inc(HexPos, 2);
    end;
end;
Delphi-Quellcode:
s := '0a,1d,4f,7c';
s := HexToBinStr(s);
WriteBinaryData('ID', s[1], length(s));
  Mit Zitat antworten Zitat