I'm having trouble converting a Decimal to its Hex signed 2's complement. I use this site to check if my conversions are correct but none seems to be working.
Example:
0002159721(Decimal) when converted to Hex signed 2's complement should be 0020F469
I was able to convert the decimal to hex using this code.
string dec = "0002159721";
string hex = Convert.ToUInt32(dec).ToString("X"); //result: 20F469
Now, I'm having trouble to get the 2's complement. This is what I have so far.
uint intVal = Convert.ToUInt32(dec, 16);
uint twosComp = ~intVal + 1;
string h = string.Format("{0:X}", twosComp);
string h1 = twosComp.ToString("X"); // result: FFDF0B97