Convert an int in string(hexaformat)

In Visual C#

I whish convert an int to a string in hexa format

I mean:

int test = 454

how convert this int to string showing : 01C6 ( in a textBox for example)

--------------------

like in C

char str[10];

int test = 454;

sprintf(str,"%04X",test);



Answer this question

Convert an int in string(hexaformat)

  • PieterE.care

    part of the problem is resolved, thank you. But there is yet a small detail: the returned string equas 1C6 instead 01C6

    like in C sprintf(string,"04X",454) -> 01C6 allways in this case convert it in 4 digits


  • thenowayman

    Use: {0:X4}

  • alwz_nikhil

    Text1.Text = string.Format("{0:X}",454);

    Happy programming


  • Convert an int in string(hexaformat)