How to convert a negative decimal number to a hexadecimal one? I know how to convert positive numbers from one base to another. The widows calculator returns a huge number something like FFFFFFFFFFFFCFC7 in hex for -12345 in dec.The value that I need to process further more is CFC7, but I don't know how to get it using C#.
Asked
Active
Viewed 311 times
2 Answers
0
Not exactly sure if that is what you need:
int i = -12345;
string test = i.ToString("X"); // test will hold: "FFFFCFC7"
int HexI = Convert.ToInt32(test, 16); // HexI will hold: -12345
![](../../users/profiles/961113.webp)
Habib
- 205,061
- 27
- 376
- 407
0
Try this:
int decimalValue = -12345;
string hexVal = String.Format("{0:x2}", decimalValue);
![](../../users/profiles/1004522.webp)
Ebad Masood
- 2,374
- 26
- 45