久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在python中將二進制字符串轉換為ascii字符串

How to convert binary string to ascii string in python?(如何在python中將二進制字符串轉換為ascii字符串?)
本文介紹了如何在python中將二進制字符串轉換為ascii字符串?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我制作了一個小 Python 程序,它從文件中讀取二進制文件并將其存儲到文本文件中,讀取文本文件并存儲二進制文件.但是,我無法讓二進制文件工作......它像這樣讀取文件:

I've made a little python program that reads binary from a file and stores it to a text file, read the text file and store the binary. But, I can't get the binary to work... it reads the files like this:

f_bin = open(bin_file,"rb")
to_bin_data = f_bin.read()
bin_data = bin(reduce(lambda x, y: 256*x+y, (ord(c) for c in to_bin_data), 0))
f_bin.close()

這個對我不起作用... 將二進制轉換為ASCII,反之亦然

類似這個網頁:http://www.roubaixinteractive.com/PlayGround/Binary_Conversion/Binary_To_Text.asp

我現在為它制作了一個很長的 if else 腳本,但感謝您的回答

推薦答案

我們來看看'hello'這個詞,它是0110100001100101011011000110110001101111

Let's take the word 'hello' which is 0110100001100101011011000110110001101111

要將其轉換回字符,我們可以使用 chrint(以 2 為基數)以及一些列表切片...

To translate that back to characters we can use chr and int (with a base of 2) and some list slicing...

''.join(chr(int(bin_text[i:i+8], 2)) for i in xrange(0, len(bin_text), 8))

如果我們想將 'hello' 轉換為二進制,我們可以使用 ord 和字符串格式化...

If we wanted to take 'hello' and convert it to binary we can use ord and string formatting...

''.join('{:08b}'.format(ord(c)) for c in 'hello')

這篇關于如何在python中將二進制字符串轉換為ascii字符串?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 精久久久 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 91精品国产91久久久久游泳池 | 特一级黄色毛片 | 国产亚洲精品精品国产亚洲综合 | 欧美一区二区大片 | www.久久久久久久久久久 | 日本小电影在线 | 成人免费淫片aa视频免费 | www.中文字幕 | 国产亚洲日本精品 | 欧美精品一区二区三区在线播放 | av在线播放网 | 在线国产99 | 中文字幕亚洲区 | 精品日韩在线观看 | 国产精品一区久久久 | 亚洲成网站 | 一区二区不卡 | 午夜手机在线视频 | 免费看91| 亚洲福利在线观看 | 国产精品久久久久久久久久免费看 | 亚洲精品国产成人 | 精品国产乱码久久久久久影片 | 欧美精品一区二区三区在线四季 | 欧美日韩一区二区三区在线观看 | 激情免费视频 | 国产激情一区二区三区 | 久久精品欧美一区二区三区不卡 | 精品一区精品二区 | 免费观看毛片 | 亚洲第一av | 中文字幕一区二区三区日韩精品 | 无码国模国产在线观看 | 99久久久无码国产精品 | 国产精品99久久久久久久久久久久 | 午夜视频网站 | 范冰冰一级做a爰片久久毛片 | 久久久噜噜噜www成人网 | 翔田千里一区二区 |