Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading certain digits from binary data

Tags:

python

c#

binary

I have one python script which i am trying to convert and stuck in one place and unable to proceed. Please check where ever i have mentioned "Stuck here" in below code. any help would be appreciated

Original Python script:

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

My C# conversion:

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();
like image 212
user1188646 Avatar asked May 18 '26 06:05

user1188646


1 Answers

Use String.Substring:

// last 6 characters
string lastsix = m.Substring(m.Length - 6);

Console.WriteLine("80{0}", lastsix);
like image 196
user7116 Avatar answered May 20 '26 18:05

user7116



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!