Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way making python produce the same result bit-wise shift left with java?

Tags:

java

python

bit

I have to transfer some function from java code to Python. but the bit shift left return different result. And Python lack of the >>> operator in java

how to make them same? Python : 6116937115306182825 << 11 = 12527487212147062425600

java : 6116937115306182825 << 11 = 2147986098276878336

like image 273
martin xu Avatar asked Jan 25 '23 13:01

martin xu


1 Answers

java has a limited number of bits(64) whereas python doesn't ... so you need to force it to the right number of bits(64)

(6116937115306182825 << 11) & 0xFFFFFFFFFFFFFFFF
like image 192
Joran Beasley Avatar answered Jan 29 '23 14:01

Joran Beasley