|
| 1 | +--- |
| 2 | +sidebar_position: 2 |
| 3 | +--- |
| 4 | + |
| 5 | +<!-- DO NOT EDIT: file generated with `pragtical gendocs` --> |
| 6 | + |
| 7 | +# bit |
| 8 | + |
| 9 | +Mike Pall bit operations library included on every Lua runtime for |
| 10 | +consistency with the patch https://github.com/LuaJIT/LuaJIT/issues/384 |
| 11 | +applied for newer Lua versions support. |
| 12 | + |
| 13 | +See: https://bitop.luajit.org/ |
| 14 | + |
| 15 | +## arshift |
| 16 | + |
| 17 | +```lua |
| 18 | +function bit.arshift(x: integer, n: integer) |
| 19 | + -> y: integer |
| 20 | +``` |
| 21 | + |
| 22 | +Returns either the bitwise logical arithmetic right-shift of its first |
| 23 | +argument by the number of bits given by the second argument. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## band |
| 28 | + |
| 29 | +```lua |
| 30 | +function bit.band(x: integer, x2: integer, ...integer) |
| 31 | + -> y: integer |
| 32 | +``` |
| 33 | + |
| 34 | +Returns the bitwise `and` of all of its arguments. |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## bnot |
| 39 | + |
| 40 | +```lua |
| 41 | +function bit.bnot(x: integer) |
| 42 | + -> y: integer |
| 43 | +``` |
| 44 | + |
| 45 | +Returns the bitwise `not` of its argument. |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## bor |
| 50 | + |
| 51 | +```lua |
| 52 | +function bit.bor(x: integer, x2: integer, ...integer) |
| 53 | + -> y: integer |
| 54 | +``` |
| 55 | + |
| 56 | +Returns the bitwise `or` of all of its arguments. |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +## bswap |
| 61 | + |
| 62 | +```lua |
| 63 | +function bit.bswap(x: integer) |
| 64 | + -> y: integer |
| 65 | +``` |
| 66 | + |
| 67 | +Swaps the bytes of its argument and returns it. This can be used to |
| 68 | +convert little-endian 32 bit numbers to big-endian 32 bit numbers or |
| 69 | +vice versa. |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## bxor |
| 74 | + |
| 75 | +```lua |
| 76 | +function bit.bxor(x: integer, x2: integer, ...integer) |
| 77 | + -> y: integer |
| 78 | +``` |
| 79 | + |
| 80 | +Returns the bitwise `xor` of all of its arguments. |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +## lshift |
| 85 | + |
| 86 | +```lua |
| 87 | +function bit.lshift(x: integer, n: integer) |
| 88 | + -> y: integer |
| 89 | +``` |
| 90 | + |
| 91 | +Returns either the bitwise logical left-shift of its first argument by the |
| 92 | +number of bits given by the second argument. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## rol |
| 97 | + |
| 98 | +```lua |
| 99 | +function bit.rol(x: integer, n: integer) |
| 100 | + -> y: integer |
| 101 | +``` |
| 102 | + |
| 103 | +Returns the bitwise left rotation of its first argument by the number of |
| 104 | +bits given by the second argument. Bits shifted out on one side are |
| 105 | +shifted back in on the other side. |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## ror |
| 110 | + |
| 111 | +```lua |
| 112 | +function bit.ror(x: integer, n: integer) |
| 113 | + -> y: integer |
| 114 | +``` |
| 115 | + |
| 116 | +Returns the bitwise right rotation of its first argument by the number of |
| 117 | +bits given by the second argument. Bits shifted out on one side are |
| 118 | +shifted back in on the other side. |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## rshift |
| 123 | + |
| 124 | +```lua |
| 125 | +function bit.rshift(x: integer, n: integer) |
| 126 | + -> y: integer |
| 127 | +``` |
| 128 | + |
| 129 | +Returns either the bitwise logical right-shift of its first argument by the |
| 130 | +number of bits given by the second argument. |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +## tobit |
| 135 | + |
| 136 | +```lua |
| 137 | +function bit.tobit(x: integer) |
| 138 | + -> y: integer |
| 139 | +``` |
| 140 | + |
| 141 | +Normalizes a number to the numeric range for bit operations and returns it. |
| 142 | +This function is usually not needed since all bit operations already |
| 143 | +normalize all of their input arguments. |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## tohex |
| 148 | + |
| 149 | +```lua |
| 150 | +function bit.tohex(x: integer, n?: integer) |
| 151 | + -> y: integer |
| 152 | +``` |
| 153 | + |
| 154 | +Converts its first argument to a hex string. The number of hex digits is |
| 155 | +given by the absolute value of the optional second argument. Positive |
| 156 | +numbers between 1 and 8 generate lowercase hex digits. Negative numbers |
| 157 | +generate uppercase hex digits. Only the least-significant 4*|n| bits are |
| 158 | +used. The default is to generate 8 lowercase hex digits. |
| 159 | + |
| 160 | +--- |
| 161 | + |
0 commit comments