将字符串转成16进制的ASCii码的值html
python:
python
使用python 内置函数repr能够将非ascii码转换成\x**的样式,以下:
linux
>>> a='咱们都是中国人' >>> print repr(a) '\xe6\x88\x91\xe4\xbb\xac\xe9\x83\xbd\xe6\x98\xaf\xe4\xb8\xad\xe5\x9b\xbd\xe4\xba\xba' >>>
好像换成非中文就不行了。shell
对于英文能够用这个:bash
>>> a=''.join('\\x%02x' % ord(x) for x in 'Hello World!') >>> print a \x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21
bash:
函数
ada@barnabas:~> echo "ABCDE" | uni2ascii -Bsepq \x0041\x0042\x0043\x0044\x0045 ada@barnabas:~> echo "ABCDE" | uni2ascii -Bsepq | ascii2uni -Bq ABCDE
C语言:post
void print_hex(const char *s) { while(*s) printf("\\x%02x", (unsigned int) *s++); printf("\n"); }
Python中文字符串与Unicode编码相互转换ui
[admin@admin ~]$ python >>> u'中文' u'\u4e2d\u6587' >>> print u'\u4e2d\u6587'.encode('utf-8') 中文 >>>
参考:编码
http://blog.chinaunix.net/uid-12453618-id-2935335.html