I have a problem, for which an answer I've been looking for too long.
In one application, written in PowerBuilder, there has been a bug (which has not been spotted on time), which went as follows - long * long results in long (not in longlong), due to what the output was somehow strange. Now I need to do the same in python. For example:
a = 3423729
b = 96300
c = a*b = 329705102700
PowerBuilder says:
c = a*b = -1007379092
Due to further tests, it seems like it is a signed 32-bit integer, but I couldn't make python return me such result. Anyways, using calc and making him go with dword multiplication, result is -1007379092. Any clue how to resolve that matter?
You can use the ctypes package:
>>> from ctypes import c_int32
>>> a = 3423729
>>> b = 96300
>>> c_int32(a*b).value
-1007379092
It seems that your application is taking the rightmost 32 bits of the result, represented as a 32 bit int.
You can use the types in the ctypes library to represent signed/unsigned integers of a specific size, in a similar manner. For a signed 32 bit int:
>>> import ctypes
>>> c = 329705102700
>>> ctypes.c_int32(c).value
-1007379092
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With