Why does bit-wise shift left return different results in Python and Java?
I'm trying to port some functionality from a Java app to Python. In Java, System.out.println(155 << 24); Returns: -1694498816 In Python: print(155 << 24) Returns 2600468480 Many other bitwise operations have worked in the same way in both languages. Why is there a different result in these two operations? EDIT: I'm trying to create a function in python to replicate how the left shift operator works in Java. Something along the lines of: def lshift(val, n): return (int(val) << n) - 0x100000000 However this doesn't seem right as (I think) it turns all numbers negatives? EDIT2: Several hours