How to convert ASCII to Hexadecimal format?

Heiko Wundram (Beenic) wundram at beenic.net
Sat Sep 22 00:52:24 PDT 2007


Am Samstag 22 September 2007 09:19:02 schrieb ronggui:
> for example:
> ASCII: a test
> HEX : 61 20 74 65 73 74

A small Python script to do the same (in case you need more control, adapt it 
as it suits you).

---
#!/usr/bin/python

from sys import argv

for c in " ".join(argv[1:]).decode("ascii"):
    print hex(ord(c))[2:].upper(),
---

[modelnine at phoenix ~]$ python test.py this is a test
74 68 69 73 20 69 73 20 61 20 74 65 73 74
[modelnine at phoenix ~]$

-- 
Heiko Wundram
Product & Application Development


More information about the freebsd-questions mailing list