1
long number = …;
// string should contain exactly 12 characters
string leastSignificant48bitsOfNumberAsHex = number.ToString("????")
long number = …;
// string should contain exactly 12 characters
string leastSignificant48bitsOfNumberAsHex = number.ToString("????")
你可以用字符串格式化做到這一點:
string leastSignificant48bitsOfNumberAsHex = String.Format("{0:X012}", number & 0xFFFFFFFFFFFF);
這將填補字符串以零,如果數字是短。
這不起作用...它只是給了我一樣的number.ToString() – Chris
應該刪除.ToString()調用(在被屏蔽的數字上);使用String.Format(「{0:X012}」,數字和0xFFFFFFFFFFFF); –
對不起,在編輯答案時忘記刪除'.ToString()'調用... – AndiDog