diff options
| author | ruki <[email protected]> | 2021-09-21 00:43:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-21 00:43:38 +0800 |
| commit | 4181bf780192cbf4be257fb7b658cfb390684a12 (patch) | |
| tree | 0d161b3124d26ef179537606880cf5dd410715b6 | |
| parent | 76be569f033423850bca8f37129ccc9b347bddb3 (diff) | |
improve bit
| -rw-r--r-- | xmake/core/base/compat/bit.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/xmake/core/base/compat/bit.lua b/xmake/core/base/compat/bit.lua index 78d5be389..c4a018382 100644 --- a/xmake/core/base/compat/bit.lua +++ b/xmake/core/base/compat/bit.lua @@ -41,5 +41,33 @@ function bit.bnot(a) return ~a end +-- bit/lshift operation +function bit.lshift(a, b) + return a << b +end + +-- bit/rshift operation +function bit.rshift(a, b) + return a >> b +end + +-- tobit operation +function bit.tobit(x) + return x & 0xffffffff +end + +-- tohex operation +function bit.tohex(x, n) + n = n or 8 + local up + if n <= 0 then + if n == 0 then return '' end + up = true + n = - n + end + x = x & (16 ^ n - 1) + return ('%0'..n..(up and 'X' or 'x')):format(x) +end + -- return module: bit return bit |
