I have the following short code:
import socketfrom sys import *host = "10.10.10.10"port = 7142buf = 1024tcpSock = socket.socket()tcpSock.settimeout(100)tcpSock.connect((host,port))## Send messagedata ='\x01\x30\x41\x30\x41\x30\x36\x02\x30\x31\x44\x36\x03\x74\x0d'if(tcpSock.send(data)): print "Sending message:",datadata = tcpSock.recv(4096) tcpSock.close()print "Received message:", data#print "Received message:", data.strip().decode("hex")
the output been:
Sending message: ☺0A0A06☻01D6♥t
Received message: ☺00AB12☻0200D60000040001♥t
Where I am stuck on is how to decode the "received message" back from the server to HEX characters
I am trying to convert a string like "testing123" into hexadecimal form in java. I am currently using BlueJ.
And to convert it back, is it the same thing except backward?
This question already has an answer here:
I found this code somewhere else on stackexchange and it works great.
char *szData = new char[str_hex.size()+1] = "\x4d\x4d\x4d\x5a\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xe0\x00\x00\x00\x0e\x1f\xba\x0e\x00\xb4\x09\xcd\x00\x00\x00\x00\x00\x00\x00\x00"; system("pause"); HANDLE hFile; DWORD dwBytesWritten = 0; TCHAR szPath[MAX_PATH] = "C:\\Users\\Jules\\Desktop\\halloskos.txt"; hFile = CreateFile (szPath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile( hFile,&hexCh,sizeof(hexCh)-1, &dwBytesWritten, NULL ); CloseHandle(hFile); delete  szData;
However, i want to pull the hex data from a text file (stored like this: 4d5a9000f4 etc...).
With fstream i can turn the contents of the text file to a string, but how can i convert this to the array shown in the code example? (So an char array like this: \x4d\x5a\x90\x00\xf4 etc...)
string str_hex = "4d5a9000f4";
char *ch_hex = new char[str_hex.size()+1] = "\x4d\x5a\x90\x00\xf4"
Thanks for your help!
How do I convert a hex string to an int in Python? I may have it as "
0xffff" or just "
Given a string that may contain any character (including a unicode characters), how can I convert this string into hexadecimal representation, and then reverse and obtain from hexadecimal this string?