我有一个 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();
最佳答案
使用String.Substring :
// last 6 characters
string lastsix = m.Substring(m.Length - 6);
Console.WriteLine("80{0}", lastsix);
关于c# - 从二进制数据中读取某些数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9150855/