View Single Post
  #1  
Old 06-06-2014, 09:13 PM
bilm bilm is offline
Junior Member
 
Join Date: Nov 2012
Posts: 3
Default Convert routine with pointer math to .NET

I do a lot of byte swapping and use an old popular routine that saves using separate multiple routines. It can swap bytes in any size of unsigned integer or byte array.

I need to convert it to .NET so no pointer math. I also need to keep the same parameters 'source', 'destination' and 'byte count'.

procedure SwapBytes(const Source; var Dest; Count: LongInt);
var pSrc, pDst : PChar;
i : LongInt;
begin
pSrc := @Source;
pDst := PChar(@Dest) + Count;
for i := 0 to Count-1 do
begin
Dec(pDst);
pDst^ := pSrc^;
Inc(pSrc);
end;
end;

I can't figure out how to do it.

Bilm
Reply With Quote