99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀使用Python內(nèi)置的模塊與函數(shù)進行不同進制的數(shù)的轉(zhuǎn)換
使用Python內(nèi)置的模塊與函數(shù)進行不同進制的數(shù)的轉(zhuǎn)換
2018-05-26
收藏

使用Python內(nèi)置的模塊與函數(shù)進行不同進制的數(shù)的轉(zhuǎn)換

這篇文章主要介紹了使用Python內(nèi)置的模塊與函數(shù)進行不同進制的數(shù)的轉(zhuǎn)換的方法,Python也使得讀取純二進制文件內(nèi)容非常方便,需要的朋友可以參考下

binascii 模塊:
它包含一個把二進制數(shù)值轉(zhuǎn)換成十六進制的函數(shù),同樣也可以反過來轉(zhuǎn)。 #binary_value是二進制數(shù)值不是字符串,也不是int型的1010    
binascii.b2a_hex(binary_value) ##binary_value 一般讀二進制文件可以得到
 
>>'89'

python自帶的builtin函數(shù):
bin(num)   十進制數(shù)值 ===》二進制字符串    
bin(10)
 
>> '0b1010'

oct(num)  十進制數(shù)值 ===》八進制字符串    
oct(10)
 
>>'012'

hex(num) 十進制數(shù)值 ===》十六進制字符串    
hex(20)
 
>>'0x14'

int(str, base) 其它進制字符串 ===》十進制的數(shù)值,其中base代表str具體是屬于哪個進制,如果是2則表示str是二進制, 默認base為十進制    
int('20')
>>20
int('10', 2)
>>2
int('10', 8)
>>8
int('20', 10)
>>20
int('20',16)
>>32

字符與數(shù)字轉(zhuǎn)換函數(shù):
chr(int)   整型 轉(zhuǎn) 字符    
chr(65)
 
>>'A',

ord(chr) 字符 轉(zhuǎn) 整型    
ord('a')
 
>>97,

最后,給一個讀取圖片文件二進制內(nèi)容的示例:
    
#!/usr/bin/env python  
#encoding: utf-8
import binascii  
 
fh = open(r'C:\Temp\img\2012517165556.png', 'rb')
a = fh.read()
#print 'raw: ',`a`,type(a)
hexstr = binascii.b2a_hex(a) #得到一個16進制的數(shù)
#print 'hex: ',hexstr, type(hexstr)
bsstr = bin(int(hexstr,16))[2:]
print 'bin: ',bsstr, type(bsstr)

1010刷屏的效果,是不是有點黑客帝國的趕腳啊,呵呵

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務(wù)器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }