문제

How can I convert a decimal number to hex with one byte format.

e.g if decimal = 15 , Output = 0x0F and Not 0xF ,
    if decimal = 240 , Output = 0xF0



Console.WriteLine("{0:x}", i) solutions gives 0xF not 0x0F. 

IN the C# there is ToINt16/32/64 but no ToINt8?

도움이 되었습니까?

해결책

You can specify the number of characters to output

var value = String.Format("0x{0:X2}", 14);

This outputs 0x0E.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top