Alex Rivera | Logout

int to hex string

Asked 2011-01-14T11:20:10.127
131

I need to convert an int to hex string.

When converting 1400 => 578 using ToString("X") or ToString("X2") but I need it like 0578.

Can anyone provide me the IFormatter to ensure that the string is 4 chars long?

c#
Edit
Report

1 Answer

204

Use ToString("X4").

The 4 means that the string will be 4 digits long.

Reference: The Hexadecimal ("X") Format Specifier on MSDN.

answered 2011-01-14T11:22:54.633

Your Answer