long number = …;
// string should contain exactly 12 characters
string leastSignificant48bitsOfNumberAsHex = number.ToString("????")
views:
44answers:
1
+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
2010-02-05 16:02:46
This doesn't work… it just gives me the same as number.ToString()
Christopher
2010-02-05 16:29:24
The .ToString() call (on the masked number) should be removed; use String.Format("{0:X012}", number
Bradley Grainger
2010-02-05 16:31:50
Sorry about that, forgot to remove the `.ToString()` call when editing the answer...
AndiDog
2010-02-05 16:40:08