Hi,
How to convert this pascal(delphi) function into java?
The function is used in a algorithm.
The trouble is that java don't have any unsigned 32bit type.
What the trick, when you cannot do bit shifting probaly,
because only signed types are aval.?
B12Ar is a array of 12 bytes(0..11), and can be anything.
"P" can be "0" or "8".
"k" can be "10" or "31".
-----------
procedure Cyc32(var Buf: B12Ar;P: byte;k: integer);
var
i : integer;
x,y : Longword;
begin
x := Buf[P];
x := x shl 8;
x := x or Buf[P + 1];
x := x shl 8;
x := x or Buf[P + 2];
x := x shl 8;
x := x or Buf[P + 3];
for i := 1 to k do
begin
// Cyclical Rotate 32 bits word right k times
y := x and 1; // Extract Carry
y := y shl 31; // Move Carry to Msb
x := x shr 1; // Do Shift
x := x or y; // Add Carry
end;
Buf[P + 3] := x;
x := x shr 8;
Buf[P + 2] := x;
x := x shr 8;
Buf[P + 1] := x;
x := x shr 8;
Buf[P] := x;
end;
-----------
--
Best regrads
M.J
How to convert this pascal(delphi) function into java?
The function is used in a algorithm.
The trouble is that java don't have any unsigned 32bit type.
What the trick, when you cannot do bit shifting probaly,
because only signed types are aval.?
B12Ar is a array of 12 bytes(0..11), and can be anything.
"P" can be "0" or "8".
"k" can be "10" or "31".
-----------
procedure Cyc32(var Buf: B12Ar;P: byte;k: integer);
var
i : integer;
x,y : Longword;
begin
x := Buf[P];
x := x shl 8;
x := x or Buf[P + 1];
x := x shl 8;
x := x or Buf[P + 2];
x := x shl 8;
x := x or Buf[P + 3];
for i := 1 to k do
begin
// Cyclical Rotate 32 bits word right k times
y := x and 1; // Extract Carry
y := y shl 31; // Move Carry to Msb
x := x shr 1; // Do Shift
x := x or y; // Add Carry
end;
Buf[P + 3] := x;
x := x shr 8;
Buf[P + 2] := x;
x := x shr 8;
Buf[P + 1] := x;
x := x shr 8;
Buf[P] := x;
end;
-----------
--
Best regrads
M.J
Comment