views:

44

answers:

1
long number = …;

// string should contain exactly 12 characters
string leastSignificant48bitsOfNumberAsHex = number.ToString("????")
+4  A: 

You can do it with string formatting:

string leastSignificant48bitsOfNumberAsHex = String.Format("{0:X012}", number & 0xFFFFFFFFFFFF);

This will fill up the string with zeroes if the number is shorter.

AndiDog
This doesn't work… it just gives me the same as number.ToString()
Christopher
The .ToString() call (on the masked number) should be removed; use String.Format("{0:X012}", number
Bradley Grainger
Sorry about that, forgot to remove the `.ToString()` call when editing the answer...
AndiDog