-1

I've got a simple question i have got a long value presented in this way

long value = 0x001f0347

Now is there's a way to convert it to string that looks the same:

string value = "0x001f0347";

I have tried some converters but no luck.

Wojciech Szabowicz
  • 3,646
  • 5
  • 43
  • 87

1 Answers1

1

Try formatting ("x8" format string - 8 hexadecimal digits):

  long value = 0x001f0347;

  string result = "0x" + value.ToString("x8");

If you prefer Convert then convert using toBase == 16 and pad left up to 8 symbols

  string result = "0x" + Convert.ToString(value, 16).PadLeft(8, '0');
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215