function HexToBin(HexStr: String): String;
const
BinLst1: array ['0'..'9'] of String[4]
= ('0000','0001','0010','0011','0100','0101','0110','0111','1000','1001');
BinLst2: array ['A'..'F'] of String[4]
= ('1010','1011','1100','1101','1110','1111');
HexChars: set of char = ['0'..'9', 'A'..'F', 'a'..'f'];
var
I, X: Integer;
ch: Char;
begin
X:= 0; Result:= '';
for I:= 1 to Length(HexStr) do
if HexStr in HexChars then begin
X:= I; Break;
end;
if X = 0 then Exit;
for I:= X to length(HexStr) do begin
ch:= upcase(HexStr);
case ch of
'0'..'9': Result:= Result + BinLst1[ch];
'A'..'F': Result:= Result + BinLst2[ch];
else Break;
end;{case}
end;
end;