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

從十六進(jìn)制轉(zhuǎn)換為二進(jìn)制而不丟失前導(dǎo)0的python

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

問題描述

我在像

h = '00112233aabbccddee'

我知道我可以使用以下方法將其轉(zhuǎn)換為二進(jìn)制:

I know I can convert this to binary with:

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

但是,這會(huì)丟失前導(dǎo) 0.有沒有辦法在不丟失 0 的情況下進(jìn)行這種轉(zhuǎn)換?或者最好的方法是在轉(zhuǎn)換之前計(jì)算前導(dǎo) 0 的數(shù)量,然后在之后添加它.

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.

推薦答案

我認(rèn)為沒有辦法默認(rèn)保留這些前導(dǎo)零.

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

每個(gè)十六進(jìn)制數(shù)字轉(zhuǎn)換為 4 個(gè)二進(jìn)制數(shù)字,因此新字符串的長(zhǎng)度應(yīng)該是原始字符串大小的 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)

這篇關(guān)于從十六進(jìn)制轉(zhuǎn)換為二進(jìn)制而不丟失前導(dǎo)0的python的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測(cè)和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測(cè)圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測(cè)圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲网站在线观看 | 免费在线黄 | 久久久青草婷婷精品综合日韩 | 国精久久 | 久久精品99国产精品日本 | 亚洲人一区 | 国产视频亚洲视频 | 99国产精品久久久 | 91麻豆精品国产91久久久更新资源速度超快 | 亚洲成人国产精品 | www久久av | 久久亚洲一区二区 | aaaa一级毛片 | 亚洲高清在线观看 | 婷婷毛片| 成人免费视频久久 | 精品国产一区二区在线 | 欧美色偷拍 | aaa一区| 亚洲一区网站 | 中文字幕在线免费视频 | 色资源在线| 精品国产乱码久久久久久图片 | 特黄特色大片免费视频观看 | 欧美性大战久久久久久久蜜臀 | 欧美一区二区三区在线观看 | 999热视频| 国产精品久久国产精品 | 九九在线精品视频 | 欧美日韩黄 | 91日韩在线 | 日韩欧美在线播放 | 欧美激情久久久 | 7777在线视频免费播放 | 亚洲一区 中文字幕 | 国产一区二区免费 | 免费在线观看一区二区三区 | 深夜福利影院 | 欧美在线一区二区三区 | 午夜资源 | 国产一区二区三区精品久久久 |