Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Hexadecimal Conversion in Python
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Bengt Richter, post: 1846234"] Maybe the binascii module's hexlify will get you into territory more familiar to you? Python generally stores byte data as type str "strings." If you want to see the bytes as hex (a string of hex characters ;-) you can e.g., '4142433132332e2e2e010203' To convert individual character, you can use a format string on the ordinal value ... 41 42 43 31 32 33 2E 2E 2E 01 02 03 Or perhaps you really want the integer ordinal value itself? ... 65 66 67 49 50 51 46 46 46 1 2 3 (print obviously does a conversion to decimal string representation for output) If you are interested in the bits, you can check them with bit operations, e.g., ... print ''.join(chr(48+((ord(c)>>b)&1)) for b in xrange(7,-1,- 1)), ... 01000001 01000010 01000011 00110001 00110010 00110011 00101110 00101110 00101110 00000001 00000010 00000011 (cf. 41 42 42 etc above) Regards, Bengt Richter [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Hexadecimal Conversion in Python
Top