lrotl (long rotate left) function
Posted: Sat Aug 03, 2013 3:37 am
I recently had a need to use lrotl (long rotate left) on unsigned longs, so I wrote this procedure:
It's necessary to specifically handle negatives or the sign bit gets propagated down the long by >>.
Hope it's of use to someone.
Code: Select all
Procedure.l lrotl(pSource.l, pShift)
; long rotate left
; pShift is number of bits to rotate left
Protected nTmp.l, nSource.l, nTarget.l
Protected nBit0.l
nSource = pSource
If nSource < 0
nBit0 = 1 << (pShift-1)
nSource & $7FFFFFFF
EndIf
nTmp = nSource >> (32 - pShift)
nTmp | nBit0
nTarget = nSource << pShift
nTarget | nTmp
ProcedureReturn nTarget
EndProcedure
Hope it's of use to someone.