| | |
Add Hexadecimal numbers
Thread Solved |
Since hexadecimal numbers are really strings representing a numeric value, you best convert these strings to a denary (base 10) number, do the mathematical operation and change the result back to the hexadecimal. Here is an example ...
Python Syntax (Toggle Plain Text)
def add_hex2(hex1, hex2): """add two hexadecimal string values and return as such""" return hex(int(hex1, 16) + int(hex2, 16)) print add_hex2('0xff', '0xff') # 0x1fe
May 'the Google' be with you!
![]() |
Similar Threads
- max int value? (C++)
- add even (or odd) numbers from input (C++)
- C++ Random Numbers (C++)
- How to add random numbers (C++)
- Cannot resolve symbol (Java)
Other Threads in the Python Forum
- Previous Thread: comparison
- Next Thread: Play those cute little Wave files (Python)
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython






