我有一个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