如何将长格式的48个最低有效位格式化为十六进制?

时间:2010-02-05 15:53:50

标签: .net string-formatting

long number = …;

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

1 个答案:

答案 0 :(得分:4)

您可以使用字符串格式化来执行此操作:

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

如果数字较短,这将用零填充字符串。