开发者

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

开发者 https://www.devze.com 2022-12-19 13:02 出处:网络
long number = …; // string should contain exactly 12 characters string leastSignificant48bitsOfNumberAsHex = nu开发者_如何学JAVAmber.ToString(\"????\")
long number = …;

// string should contain exactly 12 characters
string leastSignificant48bitsOfNumberAsHex = nu开发者_如何学JAVAmber.ToString("????")


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消