Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- logical right shift (32bit)
- local rshift = function(value, amount)
- if amount == 0 then
- return value
- end
- if amount < 0 then
- error("illegal argument #2: shift amount must be greater than zero.")
- end
- -- first logical right shift
- if value < 0 then
- assert(value >= -0xffffffff)
- value = 0x80000000 + math.floor(value / 2)
- else
- value = math.floor(value / 2)
- end
- -- and more
- for i = 2, amount do
- value = math.floor(value / 2)
- end
- return value
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement