Domanda

I have a program that calculates offset but I do not have the source code for. I am trying to see how this is calculated using C#. The first input hex digit cannot be less than 80. This is what I have written so far but it does not calculate the offset correctly:

private void getOffSet()
{

  // Default offset
  int defaultOffset = 0x0512;

  // Input
  byte byte1input = 0x80;
  byte byte2input = 0x00;
  int inValue = byte2input + (byte1input << 8);

  // Calculate offset
  int outValue = inValue + defaultOffset;

  // Convert integer as a hex in a string variable
  string hexValue = outValue.ToString("X"); 

}

Any help correcting this function to calculate the correct offset would be greatly appreciated. Thank you before hand.

È stato utile?

Soluzione

The following function matches your list. It is, however, a wild guess of course as there is no way I can match it with the original program and I have no idea what these offsets mean.

private void getOffSet(byte one, byte two)
{
  byte baseByte = 0x80;

  int defaultOffset = 0x0418;

  int mul = (one - baseByte) % 8;

  int result = mul * 0x2000 + defaultOffset;
  result += two * 0x0020;

  Console.WriteLine(result.ToString("X"));
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top