I need to create the equivalent of the >>> Java operator (logical shift) for Int variable (32-bit) with the fastest code as possible in B4J.
The function is extensively used in some crypto related work which would be computed millions of times.
I have created this but I'm not sure if it's the best in terms of performance:
Thanks in advance if you have anything better to suggest, also using native Java code eventually.
Andrea
The function is extensively used in some crypto related work which would be computed millions of times.
I have created this but I'm not sure if it's the best in terms of performance:
B4X:
Private Sub LogicShift(n As Int, shift As Int) As Int
For i = 1 To shift
n = Bit.Or(Bit.UnsignedShiftRight(n, 1), Bit.ShiftLeft(Bit.And(n, 1), 31))
Next
Return n
End Sub
Thanks in advance if you have anything better to suggest, also using native Java code eventually.
Andrea