久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 日韩欧美在线播放 | 97国产一区二区精品久久呦 | 亚洲综合视频 | 精品国产色 | 精品伊人久久 | 国产精品麻 | 日本高清不卡视频 | 一区二区三区影院 | 亚洲精品乱码久久久久久久久久 | 精品一区av | 日韩成人在线网址 | 超碰在线97国产 | 国产成人91| 国产91在线 | 亚洲 | 99精品网| 国产区在线观看 | 日韩欧美精品在线 | 亚洲第一黄色网 | 99reav| 久久久久久国产一区二区三区 | 亚洲一区免费 | 999热视频 | 精品亚洲一区二区三区四区五区 | 毛片免费视频 | 欧美一级欧美三级在线观看 | 亚洲成人精品久久久 | 国产黄色在线观看 | 黑人巨大精品欧美一区二区免费 | 视频一区 亚洲 | 亚洲一在线| 久久一二区 | 日韩在线观看一区 | 日日夜夜精品视频 | 久久久久久99 | 色本道 | 国产一区二区精品自拍 | 国产草草视频 | 2019天天操 | 精品欧美一区免费观看α√ | 欧美日韩三区 | 精品福利在线 |