int到十六进制字符串


105

我需要将int转换为十六进制字符串。

1400 => 578使用ToString("X")或转换时ToString("X2"),我需要像0578

谁能提供给我IFormatter以确保字符串长度为4个字符?


1
这里查看数字格式。
Ariel

Answers:





3

先前的答案不适用于负数。使用短类型而不是int

        short iValue = -1400;
        string sResult = iValue.ToString("X2");
        Console.WriteLine("Value={0} Result={1}", iValue, sResult);

现在的结果是FA88

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.