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 334 times
0
-
1Look at this post http://stackoverflow.com/questions/1139957/c-sharp-convert-integer-to-hex-and-back-again – fenix2222 Jun 22 '12 at 06:32
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

Habib
- 219,104
- 29
- 407
- 436
0
Try this:
int decimalValue = -12345;
string hexVal = String.Format("{0:x2}", decimalValue);

Ebad Masood
- 2,389
- 28
- 46