c# - 从二进制数据中读取某些数字

标签 c# python binary

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

相关文章:

c# - 为什么 mvcaction4 代码片段没有反应?

binary - 任何语言的十六进制到二进制角度测量 (BAMS)

java - 如何在 java ArrayList<Long> 中进行二进制搜索?

c# - 如何在 MySQL 中执行此操作

c# - 在 SQL Server 上跟踪 View

c# - .Net 应用程序中未将安全标志设置为 Cookie

Python BeautifulSoup 给 findAll 多个标签

python - 在 Python 中显示透明且没有背景或窗口的图像

python - 使用 django Rest 框架将 Base 64 编码的字符串转换为可下载的 pdf

python - 从二进制字符串python写入mp4文件