title: Convert C++ function to C#
body: <p>I am trying to port the following C++ function to C#:</p>
  
  <pre><code>QString Engine::FDigest(const QString &amp; input)
  {
      if(input.size() != 32) return "";
  
      int idx[] = {0xe, 0x3, 0x6, 0x8, 0x2},
          mul[] = {2, 2, 5, 4, 3},
          add[] = {0x0, 0xd, 0x10, 0xb, 0x5},
          a, m, i, t, v;
  
      QString b;
      char tmp[2] = { 0, 0 };
  
      for(int j = 0; j &lt;= 4; j++)
      {
          a = add[j];
          m = mul[j];
          i = idx[j];
  
          tmp[0] = input[i].toAscii();
          t = a + (int)(strtol(tmp, NULL, 16));
          v = (int)(strtol(input.mid(t, 2).toLocal8Bit(), NULL, 16));
  
          snprintf(tmp, 2, "%x", (v * m) % 0x10);
          b += tmp;
      }
  
      return b;
  }
  </code></pre>
  
  <p>Some of this code is easy to port however I'm having problems with this part:</p>
  
  <pre><code>tmp[0] = input[i].toAscii();
  t = a + (int)(strtol(tmp, NULL, 16));
  v = (int)(strtol(input.mid(t, 2).toLocal8Bit(), NULL, 16));
  
  snprintf(tmp, 2, "%x", (v * m) % 0x10);
  </code></pre>
  
  <p>I have found that <code>(int)strtol(tmp, NULL, 16)</code> equals <code>int.Parse(tmp, "x")</code> in C# and <code>snprintf</code> is <code>String.Format</code>, however I'm not sure about the rest of it.</p>
  
  <p>How can I port this fragment to C#?</p>