Chris
Chris

Reputation: 3712

How do I get the 48 least significant bits of a long formatted as hex?

long number = …;

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

Upvotes: 1

Views: 152

Answers (1)

AndiDog
AndiDog

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

Related Questions