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

從十六進制轉換為二進制而不丟失前導0的python

Converting from hex to binary without losing leading 0#39;s python(從十六進制轉換為二進制而不丟失前導0的python)
本文介紹了從十六進制轉換為二進制而不丟失前導0的python的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在像

h = '00112233aabbccddee'

我知道我可以使用以下方法將其轉換為二進制:

I know I can convert this to binary with:

h = bin(int(h, 16))[2:]

但是,這會丟失前導 0.有沒有辦法在不丟失 0 的情況下進行這種轉換?或者最好的方法是在轉換之前計算前導 0 的數量,然后在之后添加它.

However, this loses the leading 0's. Is there anyway to do this conversion without losing the 0's? Or is the best way to do this just to count the number of leading 0's before the conversion then add it in afterwards.

推薦答案

我認為沒有辦法默認保留這些前導零.

I don't think there is a way to keep those leading zeros by default.

每個十六進制數字轉換為 4 個二進制數字,因此新字符串的長度應該是原始字符串大小的 4 倍.

Each hex digit translates to 4 binary digits, so the length of the new string should be exactly 4 times the size of the original.

h_size = len(h) * 4

然后,您可以使用 .zfill 將零填充到您想要的大小:

Then, you can use .zfill to fill in zeros to the size you want:

h = ( bin(int(h, 16))[2:] ).zfill(h_size)

這篇關于從十六進制轉換為二進制而不丟失前導0的python的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲精品九九 | 日韩精品视频在线观看一区二区三区 | 日韩午夜电影在线观看 | 国产日韩在线观看一区 | 日韩精品视频在线观看一区二区三区 | 精品av | 女同videos另类 | 蜜臀网 | 91免费入口| 国产香蕉视频在线播放 | 国产精品中文字幕在线 | 中文日韩在线 | 毛片免费观看 | 日韩高清在线 | 七七婷婷婷婷精品国产 | 久久国产一区二区三区 | 91看片在线观看 | 国产高清一区二区三区 | 精品国产乱码久久久久久老虎 | 91精品国产欧美一区二区成人 | 日本字幕在线观看 | 精品视频一区二区三区在线观看 | 日韩精品在线一区 | 草草精品| 久久99精品久久久久久国产越南 | wwww.8888久久爱站网 | 日韩国产精品一区二区三区 | 91精品免费视频 | 成人精品鲁一区一区二区 | 毛片一区二区三区 | 欧美久久国产 | 成人在线视频一区 | 污书屋 | 日韩1区2区 | 91久久精品 | 国产一级片91 | 国产免费一区二区 | 亚洲综合色视频在线观看 | 国产高清自拍视频在线观看 | 久久久久免费观看 | 超碰精品在线 |