Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting from HEX to ANSI
#6
(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):
b'ä¼qh8±\æüÕ'
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

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=' ')
Reply


Messages In This Thread
Converting from HEX to ANSI - by Blackklegend - Oct-23-2018, 10:54 PM
RE: Converting from HEX to ANSI - by Larz60+ - Oct-23-2018, 11:53 PM
RE: Converting from HEX to ANSI - by micseydel - Oct-23-2018, 11:55 PM
RE: Converting from HEX to ANSI - by Blackklegend - Oct-24-2018, 11:51 AM
RE: Converting from HEX to ANSI - by snippsat - Oct-24-2018, 01:31 PM
RE: Converting from HEX to ANSI - by Blackklegend - Oct-24-2018, 02:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ANSI not working for change of text colors BliepMonster 10 3,844 Nov-10-2022, 09:28 AM
Last Post: BliepMonster
  Help ANSI character and python... sid4g 2 2,540 Mar-19-2020, 06:08 PM
Last Post: sid4g

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020