Converter procedure em Delphi para cSharp
A chamada da procedure é a seguinte: HexTextToBinary( Result, PChar(tmpStr), Length( tmpStr ) );
Primeiro como converter este PChar em c#?
procedure HexTextToBinary( AHexText: string;
ABuffer: pointer;
ALength: integer );
var
ii: integer;
tmpBuf: ^byte;
Bits: char;
begin
tmpBuf := ABuffer;
if Length( AHexText ) < ALength * 2 then
raise Exception.Create( ''''Invalid text in HexTextToBinary'''' );
for ii := 0 to ALength - 1 do begin
Bits := AHexText[ ii * 2 + 1 ];
case Bits of
''''0''''..''''9'''': tmpBuf^ := 16 * ( Ord( Bits ) - Ord( ''''0'''' ));
''''A''''..''''F'''': tmpBuf^ := 16 * ( Ord( Bits ) - Ord( ''''A'''' ) + 10 );
end;
Bits := AHexText[ ii * 2 + 2 ];
case Bits of
''''0''''..''''9'''': tmpBuf^ := tmpBuf^ + Ord( Bits ) - Ord( ''''0'''' );
''''A''''..''''F'''': tmpBuf^ := tmpBuf^ + Ord( Bits ) - Ord( ''''A'''' ) + 10;
end;
Inc( tmpBuf );
end;
end;
Primeiro como converter este PChar em c#?
procedure HexTextToBinary( AHexText: string;
ABuffer: pointer;
ALength: integer );
var
ii: integer;
tmpBuf: ^byte;
Bits: char;
begin
tmpBuf := ABuffer;
if Length( AHexText ) < ALength * 2 then
raise Exception.Create( ''''Invalid text in HexTextToBinary'''' );
for ii := 0 to ALength - 1 do begin
Bits := AHexText[ ii * 2 + 1 ];
case Bits of
''''0''''..''''9'''': tmpBuf^ := 16 * ( Ord( Bits ) - Ord( ''''0'''' ));
''''A''''..''''F'''': tmpBuf^ := 16 * ( Ord( Bits ) - Ord( ''''A'''' ) + 10 );
end;
Bits := AHexText[ ii * 2 + 2 ];
case Bits of
''''0''''..''''9'''': tmpBuf^ := tmpBuf^ + Ord( Bits ) - Ord( ''''0'''' );
''''A''''..''''F'''': tmpBuf^ := tmpBuf^ + Ord( Bits ) - Ord( ''''A'''' ) + 10;
end;
Inc( tmpBuf );
end;
end;
Fernando Ito
Curtidas 0