function HexToBinStrW(const HexStr : string) : WideString;
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
HexSize : Integer;
HexPos : Integer;
begin
result := '';
HexSize := length(HexStr);
HexPos := 0;
while ((HexSize - HexPos) > 1) do
begin
while not (HexStr[HexPos+1] in ValidHexChars) do
begin
Inc(HexPos);
If ((HexSize - HexPos) < 1) then
Break;
end;
If ((HexSize - HexPos) < 4) then
Break;
result := result + WideChar( (Convert[HexStr[HexPos+1]] shl 12) +
(Convert[HexStr[HexPos+2]] shl 8) +
(Convert[HexStr[HexPos+3]] shl 4) +
(Convert[HexStr[HexPos+4]] ) );
Inc(HexPos, 4);
end;
end;