I'm writing a GUI to build transaction messages to a payment processing platform. You put what you want in each field and it builds the message in ascii hex. I have a text widget that displays the hex as a string so you can edit it. Example for 12 dollars is below:
303030303030303031323030
now, when I send it to the processor I have to encode it. This makes it convert what is already ascii hex, into ascii hex again...
333033303330333033303330333033303331333233303330
The hex is stored in a string variable so it can be displayed and edited from the GUI's text widget. I need to convert it to hex for socket send, without re-encoding it to ascii. Any ideas?
I haven't found a way to solve this problem yet:
From a user Input the script receives a string, e.g.:
"ABCD.00.00"
The . indicates an hex character, the script should output the follwing string:
"ABCD\x00\x00"
I tried the following:
cmd = "ABCD.00.00"if "." in cmd: splitted = cmd.split(".") cmd = splitted[0] i = 1 while i < len(splitted): cmd = cmd+"\\x"+splitted[i] i = i + 1return(cmd)
But the returned string has two backslashes, and so the hex characters can not be recognized:
"ABCD\\x00\\x00"
Does anybody has a clue to solve this problem?Many thanks in advance
I am trying to use str.encode()
but I get
>>> "hello".encode(hex)Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: must be string, not builtin_function_or_method
I have tried a bunch of variations and they seem to all work in Python 2.5.2, so what do I need to do to get them to work in Python 3.1?
Possible Duplicate:
C++ convert hex string to signed integer
I allready searched on google but didn't find any help.So heres my problem:I have strings that allready contains hex code e.g.: string s1 = "5f0066"and i want to convert this string to hex.I need to compare the string with hex code i've read in a binary file.
(Just need the basic idea how to convert the string)5fBest regards and thanks.
Edit: Got the binary file info in the format of unsigned char. SO its 0x5f...WOuld like to have teh string in the same format
I am trying to convert the hexadecimal values of an array into characters of another one. Here is the only way, I could find but not working.
Thank you for your help !
char tmp[] = {0x81, 0x00, 0x00, 0x00, 0x12, 0x05};char new[12];for (int i = 0; i < 6; i++) { printf(" %x", tmp[i]); sprintf(new + i, "%x", tmp[i]);}for (int i = 0; i < 12; i++) { printf(" %c", new[i]);}printf("new: %s\n", new);
Here is the output :
81 0 0 0 12 5 8 0 0 0 1 5new: 800015
So, it lacks some bytes ...
Maison - Plan du site - Intimité - Links - Copyright © 2019 Cortex IT Ltd : Contact : admin @ cortexit.co.uk
Please note that by viewing our site you agree to our use of cookies (see Intimité for details). You will only see this message once.