Reputation: 3712
long number = …;
// string should contain exactly 12 characters
string leastSignificant48bitsOfNumberAsHex = number.ToString("????")
Upvotes: 1
Views: 152
Reputation: 70188
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.
Upvotes: 3