converting binary to utf-8 in python
问题 I have a binary like this: 1101100110000110110110011000001011011000101001111101100010101000 and I want to convert it to utf-8. how can I do this in python? 回答1: Cleaner version: >>> test_string = '1101100110000110110110011000001011011000101001111101100010101000' >>> print ('%x' % int(test_string, 2)).decode('hex').decode('utf-8') نقاب Inverse (from @Robᵩ's comment): >>> '{:b}'.format(int(u'نقاب'.encode('utf-8').encode('hex'), 16)) 1: