Module Bit
An instance of the Bit class.
Bit class in not accessible for the user. For more information visit: Bitop
Info:
- Copyright: Debaru Kft. 2017
- Release:
- License: GNU
- Author: Debaru Kft
Functions
| tobit (x) | Converts to bit. |
| tohex (x) | Converts to hex. |
| bnot (x) | Negates the input. |
| bor (x1, x2, ...) | Makes bitwise OR operation between input variables. |
| band (x1, x2, ...) | Makes bitwise AND operation between input variables. |
| bxor (x1, x2, ...) | Makes bitwise XOR operation between input variables. |
| lshift (x, n) | Shifts the input variable to the left by the number of bits given by the second argument. |
| rshift (x, n) | Shifts the input variable to the right by the number of bits given by the second argument. |
| arshift (x, n) | Returns bitwise arithmetic right-shift of the first argument by the number of bits given by the second argument. |
| rol (x, n) | Rotates to the left the first argument by the number of bits given by the second argument. |
| ror (x, n) | Rotates to the right the first argument by the number of bits given by the second argument. |
| bswap (x) | Swaps lower and higher bytes of the argument. |
Functions
- tobit (x)
-
Converts to bit.
Parameters:
- x any
Usage:
print(0xffffffff) --> 4294967295 (*) print(bit.tobit(0xffffffff)) --> -1 printx(bit.tobit(0xffffffff)) --> 0xffffffff print(bit.tobit(0xffffffff + 1)) --> 0 print(bit.tobit(2^40 + 1234)) --> 1234
- tohex (x)
-
Converts to hex.
Parameters:
- x any
Usage:
print(bit.tohex(1)) --> 00000001 print(bit.tohex(-1)) --> ffffffff print(bit.tohex(0xffffffff)) --> ffffffff print(bit.tohex(-1, -8)) --> FFFFFFFF print(bit.tohex(0x21, 4)) --> 0021 print(bit.tohex(0x87654321, 4)) --> 4321
- bnot (x)
-
Negates the input.
Parameters:
- x any
Usage:
print(bit.bnot(0)) --> -1 printx(bit.bnot(0)) --> 0xffffffff print(bit.bnot(-1)) --> 0 print(bit.bnot(0xffffffff)) --> 0 printx(bit.bnot(0x12345678)) --> 0xedcba987
- bor (x1, x2, ...)
-
Makes bitwise OR operation between input variables.
Parameters:
- x1 Any
- x2 Any
- ... Any
Usage:
print(bit.bor(1, 2, 4, 8)) --> 15
- band (x1, x2, ...)
-
Makes bitwise AND operation between input variables.
Parameters:
- x1 Any
- x2 Any
- ... Any
Usage:
printx(bit.band(0x12345678, 0xff)) --> 0x00000078
- bxor (x1, x2, ...)
-
Makes bitwise XOR operation between input variables.
Parameters:
- x1 Any
- x2 Any
- ... Any
Usage:
printx(bit.bxor(0xa5a5f0f0, 0xaa55ff00)) --> 0x0ff00ff0
- lshift (x, n)
-
Shifts the input variable to the left by the number of bits
given by the second argument.
Parameters:
- x Any
- n int
Usage:
print(bit.lshift(1, 0)) --> 1 print(bit.lshift(1, 8)) --> 256 print(bit.lshift(1, 40)) --> 256 printx(bit.lshift(0x87654321, 12)) --> 0x54321000
- rshift (x, n)
-
Shifts the input variable to the right by the number of bits
given by the second argument.
Parameters:
- x Any
- n int
Usage:
print(bit.rshift(256, 8)) --> 1 print(bit.rshift(-256, 8)) --> 16777215 printx(bit.rshift(0x87654321, 12)) --> 0x00087654
- arshift (x, n)
-
Returns bitwise arithmetic right-shift of the first argument by the number of bits
given by the second argument.
Parameters:
- x Any
- n int
Usage:
print(bit.arshift(256, 8)) --> 1 print(bit.arshift(-256, 8)) --> -1 printx(bit.arshift(0x87654321, 12)) --> 0xfff87654
- rol (x, n)
-
Rotates to the left the first argument by the number of bits
given by the second argument.
Parameters:
- x Any
- n int
Usage:
printx(bit.rol(0x12345678, 12)) --> 0x45678123
- ror (x, n)
-
Rotates to the right the first argument by the number of bits
given by the second argument.
Parameters:
- x Any
- n int
Usage:
printx(bit.ror(0x12345678, 12)) --> 0x67812345
- bswap (x)
-
Swaps lower and higher bytes of the argument.
Parameters:
- x Any
Usage:
printx(bit.bswap(0x12345678)) --> 0x78563412 printx(bit.bswap(0x78563412)) --> 0x12345678