How to convert uint64 in C into Python 32bit Object [ I am using Python2.2 ]
Hi all I am new to C and python ... I want to convert C data type uint64 variable into the Python 32bit Object. I am currently using Python 2.2 [ It is necessary to use it ] Kindly give your suggestion how and in which way I can achieve this task. Looking forward for your positive feedback. Cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert uint64 in C into Python 32bit Object [ I am using Python2.2 ]
On Dec 11, 4:45 am, John Machin <[EMAIL PROTECTED]> wrote: > On Dec 11, 9:49 am, Explore_Imagination <[EMAIL PROTECTED]> > wrote: > > > Hi all > > > I am new to C and python ... I want to convert C data type uint64 > > variable into the Python 32bit Object. I am currently using Python 2.2 > > [ It is necessary to use it ] > > > Kindly give your suggestion how and in which way I can achieve this > > task. > > I'm not sure what you mean by "the Python 32bit Object". A Python int > object holds a signed 32-bit integer. A Python long object holds a > signed integer of arbitrary size. You will need to convert your uint64 > into a Python long; then, if necessary, check that the result will fit > in an int (result <= sys.maxint). > > If the "C variable" is in an 8-byte string that you have read from a > file, the unpack function in the struct module will do the job. > Assuming your computer is little-endian: > > >>> maxu64 = '\xff' * 8 # example input string > >>> import struct > >>> result = struct.unpack(' >>> result > > 18446744073709551615L>>> 2 ** 64 - 1 > > 18446744073709551615L > > If however you mean that in C code you need to build a Python object > to pass over to Python code: According to the Python/C API Reference > Manual (http://www.python.org/doc/2.2.3/api/longObjects.html): > > PyObject* PyLong_FromUnsignedLongLong(unsigned long long v) > Return value: New reference. > Returns a new PyLongObject object from a C unsigned long long, or > NULL on failure. > > If however you mean something else, > > HTH, > John Thanks for your feedback ... Actually I want to pass unit64 variable in C to python but at the same time I want to have a generic code which should work on both little-endian and big endian architectures Any suggestions ? -- http://mail.python.org/mailman/listinfo/python-list
Mapping 64 bit int from C to Python-2.2
Hi I want to map 64 bit integers from C to python. I must use Python 2.2 BUT There is no support for 64 bits integers in Python2.2 (Supported in 2.5). Now the problem is that I have these four variables: unit32_t a,b,c; uint64_t w,x,y,z; I use this funtion to map values: Py_BuildValue( "(lll)", a,b,c,w,x,y,z ); As I access 32 bit values in Python it works fine BUT 64 bit intergers in Pythong give garbage values . I think there may be a case of overflow when 64 bit values in C are mapped to python. Any Suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: Mapping 64 bit int from C to Python-2.2
On Mar 9, 5:57 pm, MRAB wrote: > Explore_Imagination wrote: > > Hi > > > I want to map 64 bit integers from C to python. I must use Python 2.2 > > BUT There is no support for 64 bits integers in Python2.2 (Supported > > in 2.5). > > > Now the problem is that I have these four variables: > > > unit32_t a,b,c; > > uint64_t w,x,y,z; > > > I use this funtion to map values: > > > Py_BuildValue( "(lll)", a,b,c,w,x,y,z ); > > > As I access 32 bit values in Python it works fine BUT 64 bit intergers > > in Pythong give garbage values . I think there may be a case of > > overflow when 64 bit values in C are mapped to python. > > > Any Suggestions? > > Split the 64-bit values into 2 x 32-bit values? I have tried by splitting 64-bit values but still it doesn't make any difference :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Mapping 64 bit int from C to Python-2.2
On Mar 9, 5:57 pm, MRAB wrote: > Explore_Imagination wrote: > > Hi > > > I want to map 64 bit integers from C to python. I must use Python 2.2 > > BUT There is no support for 64 bits integers in Python2.2 (Supported > > in 2.5). > > > Now the problem is that I have these four variables: > > > unit32_t a,b,c; > > uint64_t w,x,y,z; > > > I use this funtion to map values: > > > Py_BuildValue( "(lll)", a,b,c,w,x,y,z ); > > > As I access 32 bit values in Python it works fine BUT 64 bit intergers > > in Pythong give garbage values . I think there may be a case of > > overflow when 64 bit values in C are mapped to python. > > > Any Suggestions? > > Split the 64-bit values into 2 x 32-bit values? I have tried by splitting 64-bit values but still it doesn't make any difference :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Mapping 64 bit int from C to Python-2.2
On Mar 9, 5:57 pm, MRAB wrote: > Explore_Imagination wrote: > > Hi > > > I want to map 64 bit integers from C to python. I must use Python 2.2 > > BUT There is no support for 64 bits integers in Python2.2 (Supported > > in 2.5). > > > Now the problem is that I have these four variables: > > > unit32_t a,b,c; > > uint64_t w,x,y,z; > > > I use this funtion to map values: > > > Py_BuildValue( "(lll)", a,b,c,w,x,y,z ); > > > As I access 32 bit values in Python it works fine BUT 64 bit intergers > > in Pythong give garbage values . I think there may be a case of > > overflow when 64 bit values in C are mapped to python. > > > Any Suggestions? > > Split the 64-bit values into 2 x 32-bit values? I have tried by splitting 64-bit values but still it doesn't make any difference :( -- http://mail.python.org/mailman/listinfo/python-list
Mapping 64 bit int from C to Python-2.2 ?????
Hi I want to map 64 bit integers from C to python. I must use Python 2.2 BUT There is no support for 64 bits integers in Python2.2 (Supported in 2.5). Now the problem is that I have following variables: unit32_t a,b,c; uint64_t w,x,y,z; I use this funtion to map values: Py_BuildValue( "(lll)", a,b,c,w,x,y,z ); As I access 32 bit values in Python it works fine BUT 64 bit intergers in Pythong give garbage values . I think there may be a case of overflow when 64 bit values in C are mapped to python. I have tried by splitting 64-bit values but still it doesn't make any difference :( Any Suggestions? -- http://mail.python.org/mailman/listinfo/python-list