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

Python:如何從二進制轉換為 base 64 并返回?

Python: How do I convert from binary to base 64 and back?(Python:如何從二進制轉換為 base 64 并返回?)
本文介紹了Python:如何從二進制轉換為 base 64 并返回?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

假設我有一些二進制值:

Lets say I have some binary value:

0b100

并希望將其轉換為 base64

and want to convert it to base64

執行 base64.b64decode(0b100) 告訴我它需要一個字符串,而不是一個 int....現在,我不想使用字符串.

doing base64.b64decode(0b100) tells me that it is expecting a string, not an int.... now, I don't want to work with strings.

那么,誰能指出我將二進制數轉換為 base64 數的正確方向?謝謝!

So, could anyone point me in the right direction for converting binary numbers to base64 numbers? thanks!

=D

推薦答案

取決于你如何表示值 0b100

>>> import struct
>>> val = 0b100
>>> print struct.pack('I', val).encode('base64')
BAAAAA==

這會將您的值轉換為原生字節序的 4 字節整數,并將該值編碼為 base64.您需要指定數據的寬度,因為 base64 確實用于以可打印字符表示二進制數據.

This will turn your value into a 4-byte integer in native endianness, and encode that value into base64. You need to specify the width of your data as base64 is really made for representing binary data in printable characters.

您通常可以通過 struct 的函數將數據編碼為一串字節,然后編碼為 base64.確保在解碼時使用相同的數據布局和字節序.

You can typically encode data as a string of bytes via struct's functions, and then encode into base64. Ensure you're using the same data layout and endianess when decoding.

這篇關于Python:如何從二進制轉換為 base 64 并返回?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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成人午夜性a一级毛片 | 日韩国产欧美视频 | 久草在线| 精品国产一区二区三区观看不卡 | 一区二区在线免费观看 | 日韩一区在线播放 | 精品国产一区二区三区在线观看 | 免费v片| 欧美久久一级 | 久久国内 | 成人一区二区三区 | 欧美精品成人 | 成人日韩| 爱操影视 | 国产欧美一区二区三区久久手机版 | 日韩成人在线播放 | 久久国产精彩视频 | 久久精品国产一区二区三区不卡 | 午夜大片| 欧美不卡在线 | 亚州精品天堂中文字幕 | 黄网站在线播放 | 日本精品裸体写真集在线观看 | 欧美久久久久久 | 亚洲在线一区二区三区 | 伊人艹 | 精品熟人一区二区三区四区 | 国产精品久久久久久久久免费桃花 | 午夜影视网 | 久久久久久久久一区 | 日本一区二区高清视频 | 亚洲在线一区 | 日韩免费看片 | 亚洲精品一区二区另类图片 | 亚洲热在线视频 | 国产成人精品综合 | 免费毛片www com cn |