bit.ashr
Lua function

bit.ashr

Summary

Shifts a number right, preserving sign

Prototype

n = bit.ashr (num, bits)



Description

This takes two arguments. The first is converted to signed 'long long' (64-bit integer), the second to unsigned 'long long' (64-bit unsigned integer). The first argument is shifted right the number of bits in the second argument.

Use this version for shifting signed numbers right, as it preserves the sign. (The other version, bit.shr, will shift the sign bit into the number part).

eg.


print (bit.ashr (-1024, 6)) --> -16



See Also ...

Topics

DOC_lua_base Lua base functions
DOC_lua_bc Lua bc (big number) functions
DOC_lua_bit Lua bit manipulation functions
DOC_lua_coroutines Lua coroutine functions
DOC_lua_debug Lua debug functions
DOC_lua_io Lua io functions
DOC_lua_math Lua math functions
DOC_lua_os Lua os functions
DOC_lua_package Lua package functions
DOC_lua_rex Lua PCRE regular expression functions
DOC_lua Lua script extensions
DOC_lua_string Lua string functions
DOC_lua_tables Lua table functions
DOC_lua_utils Lua utilities
DOC_scripting Scripting

Lua functions

LUA_bit.band bit.band (Bitwise 'and')
LUA_bit.bor bit.bor (Bitwise 'or')
LUA_bit.mod bit.mod (Bitwise 'modulus' (remainder after integer divide))
LUA_bit.neg bit.neg (Bitwise negate (ones complement))
LUA_bit.shl bit.shl (Shifts a number left)
LUA_bit.shr bit.shr (Shifts a number right)
LUA_bit.tonumber bit.tonumber (Convert a string into a number)
LUA_bit.tostring bit.tostring (Convert a number into a string)
LUA_bit.xor bit.xor (Bitwise 'exclusive or')

(Help topic: lua=bit.ashr)

DOC_contents Documentation contents page