本文介绍了在python中将二进制文件转换为utf-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的二进制文件: 1101100110000110110110011000001011011000101001111101100010101000
I have a binary like this: 1101100110000110110110011000001011011000101001111101100010101000
,我想将其转换为utf-8.我该如何在python中做到这一点?
and I want to convert it to utf-8.how can I do this in python?
推荐答案
更干净的版本:
>>> test_string = '1101100110000110110110011000001011011000101001111101100010101000'
>>> print ('%x' % int(test_string, 2)).decode('hex').decode('utf-8')
نقاب
反(来自@Robᵩ的评论):
Inverse (from @Robᵩ's comment):
>>> '{:b}'.format(int(u'نقاب'.encode('utf-8').encode('hex'), 16))
1: '1101100110000110110110011000001011011000101001111101100010101000'
这篇关于在python中将二进制文件转换为utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!