我有一個python腳本,我試圖轉換並卡在一個地方,無法繼續。請在下面的代碼中查看我曾經提到的「卡在這裏」。任何幫助,將不勝感激從二進制數據讀取某些數字
原始Python腳本:
import hashlib
meid = raw_input("Enter an MEID: ").upper()
s = hashlib.sha1(meid.decode('hex'))
#decode the hex MEID (convert it to binary!)
pesn = "80" + s.hexdigest()[-6:].upper()
#put the last 6 digits of the hash after 80
print "pESN: " + pesn
我的C#轉換:
UInt64 EsnDec = 2161133276;
string EsnHex=string.Format("{0:x}", EsnDec);
string m = Convert.ToString(Convert.ToUInt32(EsnHex, 16), 2);
/*---------------------------------------------
Stuck here. Now m got complete binary data
and i need to take last 6 digits as per python
script and prefix "80".
---------------------------------------------*/
Console.WriteLine(m);
Console.Read();
[m.Substring似乎是正確的選擇。](http://msdn.microsoft.com/en-us/library/system.string.substring.aspx) – user7116 2012-02-05 16:32:05
同意。要獲取字符串's'的最後'n'數字,可以使用:'s.Substring(s.Length - n)'。 – Douglas 2012-02-05 16:33:39