In JavaScript, we can use bitwise left-shift and right-shift operators to truncate a float and round it down to the nearest integer.
Example:
console.log(2.667 << 0); //outputs 2
console.log(2.667 >> 0); //outputs 2
These bitwise operators also do the same thing:
console.log(2.667 | 0); //outputs 2
console.log(0 | 2.667); //outputs 2
console.log(~~2.667); //outputs 2
In Python, however, the same operations return errors.
Is there any equivalent in Python -- using bitwise operators? Or must I use int() and floor division to achieve what I'm looking for?
round,floor, orint, depending on your context.