WeaselFox
WeaselFox

Reputation: 7380

how to translate "0x%llx" from C to python

I'm reading some strings from a memory buffer, written by a C program. I need to fetch them using python and print them. however when I encounter a string containing %llx python does not know how to parse this:

"unsupported format character 'l' (0x6c) at index 14"

I could use replace('%llx','%x') but than it would not be a long long.. would python handle this correctly in this case?

Upvotes: 0

Views: 615

Answers (2)

Patrick Collins
Patrick Collins

Reputation: 10594

 than it would not be a long long

Python (essentially) doesn't have any concept of a long long. If you're pulling long longs from C code, just use %x and be done with it -- you're not ever going to get values from the C code that are out of the long long range, the only issue that could arise is if you were trying to send them from Python code into C. Just use (with a new-style format string):

print('{0:x}'.format(your_int))

Upvotes: 2

OneOfOne
OneOfOne

Reputation: 99332

Tested on both Python v3.3.3 and v2.7.6 :

>>> print('%x' % 523433939134152323423597861958781271347434)
6023bedba8c47434c84785469b1724910ea

Upvotes: 1

Related Questions