1

Hi I'm trying to convert som Python code to C# I'm struck understanding this line of code

n = int(e[2:10], 16)

e is a string looking like this:

0100000180a6fa85de8dd3381cc277b046d7e3856307519d03da4e3ff5dca52de833c56951ab3e539a161df98454be311fd242407b25bf7b8e84c322f06f913d712393922bd1477d2cf3a9d2ba14bb00f8b2d7a203376afed0e1782e49ea55d43cee8e3bb8331f3f8aa81955bae8fcd118f640b4cd49d787bd8a12d57f424b371d07f08de67ab8f40bf5894288920adfe9480cfbec7deef073c3f137d71dff9d4ab967d9178648961cd2def00d376cf01dca6a4c6428243cef23eeab9791f5cd7d66f5293879b7ed83abf600f78426491c57c8a61e
Vasilis G.
  • 7,556
  • 4
  • 19
  • 29
Jens Borrisholt
  • 6,174
  • 1
  • 33
  • 67

2 Answers2

3

n = int(e[2:10], 16) takes characters 2..10 from e and interprets them as hexadecimal characters to interpret as an integer.

That is, for your input,

>>> e = '0100000180a6fa85de8dd3...'
>>> f = e[2:10]
>>> f
'00000180'
>>> int(f, 16)
384

so you should be able to do the same with something like Convert.ToInt32(e.Substring(2, 8), 16) in C#.

AKX
  • 152,115
  • 15
  • 115
  • 172
2

At first, you're using string slicing (from 2nd to 9th character) using [2:10]. Then you're converting them to (decimal) int from hexadecimal. Which will result n = 384.

Taohidul Islam
  • 5,246
  • 3
  • 26
  • 39