Oct-23-2018, 10:54 PM
(This post was last modified: Oct-23-2018, 10:55 PM by Blackklegend.)
I am basically searching for a script to convert a Hex string to Windows(ANSI)
Converting from HEX to ANSI
|
Oct-23-2018, 10:54 PM
(This post was last modified: Oct-23-2018, 10:55 PM by Blackklegend.)
I am basically searching for a script to convert a Hex string to Windows(ANSI)
Oct-23-2018, 11:53 PM
do you mean text (ASCII) ?
Oct-23-2018, 11:55 PM
Do you mean ASCII? This should be pretty easy. Loop over the string two characters at a time, call int() with those two characters and 16, then use chr() to convert the generated number into a character.
Oct-24-2018, 11:51 AM
(Oct-23-2018, 11:55 PM)micseydel Wrote: Do you mean ASCII? This should be pretty easy. Loop over the string two characters at a time, call int() with those two characters and 16, then use chr() to convert the generated number into a character. (Oct-23-2018, 11:53 PM)Larz60+ Wrote: do you mean text (ASCII) ? I think i am confusing between ASCII and 'Windows-1252'. That aside, let's say i want to convert the following string ch='E4BC716838B15CE6FCD5' to this string onscreen "ä¼qh8±\æüÕ" Here is what i did: #Convert to: "ä¼qh8±\æüÕ" # ch='E4BC716838B15CE6FCD5' for i in range(1,(len(ch)//2)+1): ph='' ph=ch[2*i-2:2*i] #the two char at a time string x=bytes.fromhex(ph) #int(x, 16) doesn't seem to work (E4,BC.. are probably the cause) print(x,end='')What the Shell shows is: b'\xe4'b'\xbc'b'q'b'h'b'8'b'\xb1'b'\\'b'\xe6'b'\xfc'b'\xd5' Which should have been(atleast what i want to get): b'ä¼qh8±\æüÕ' (My main reason for writing this script is converting 'hex string' to 'whatever these type of characters are_äæB©ó¾‡_') (Also if possible, tell me everything about the characters)
Oct-24-2018, 01:31 PM
(Oct-24-2018, 11:51 AM)Blackklegend Wrote: Which should have been(atleast what i want to get):There is mbcs encoding for Windows that can convert between ANSI and Unicode.>>> s = b'\xe4'b'\xbc'b'q'b'h'b'8'b'\xb1'b'\\'b'\xe6'b'\xfc'b'\xd5' >>> d = s.decode('mbcs') >>> d 'ä¼qh8±\\æüÕ' >>> print(d) ä¼qh8±\æüÕ >>> 'ä¼qh8±\æüÕ' == d True
Oct-24-2018, 02:28 PM
(Oct-24-2018, 01:31 PM)snippsat Wrote:(Oct-24-2018, 11:51 AM)Blackklegend Wrote: Which should have been(atleast what i want to get):There is Thank you for the tip but I went on an did it manually before reading your reply. (Oct-23-2018, 11:55 PM)micseydel Wrote: Do you mean ASCII? This should be pretty easy. Loop over the string two characters at a time, call int() with those two characters and 16, then use chr() to convert the generated number into a character. After reading this carefully I got the following code: ch="E4BC716838B15CE6FCD5" for i in range(1,(len(ch)//2)+1): Lh='' Lh=ch[2*i-2:2*i] x = int(Lh,16) print(chr(x),end=' ') |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
ANSI not working for change of text colors | BliepMonster | 10 | 7,342 |
Nov-10-2022, 09:28 AM Last Post: BliepMonster |
|
Help ANSI character and python... | sid4g | 2 | 3,173 |
Mar-19-2020, 06:08 PM Last Post: sid4g |