如何解决这个转换器十六进制到八进制像excel?

时间:2015-05-20 10:16:12

标签: c# excel

我正在尝试将十六进制转换为八进制,就像在C#中的excel一样。

在普通转换器中:

=Hex2Oct("FFF0FFFFFF") 
Answer:17776077777777

在Excel中:

=Hex2Oct("FFF0FFFFFF") 
Answer:6077777777

我怎么能解决这个问题 有人知道请建议我吗?

1 个答案:

答案 0 :(得分:0)

Excel 截断结果,因此它不正确;根据手册

https://support.office.microsoft.com/en-nz/article/HEX2OCT-function-d52055af-1be5-43c1-9319-2ce0ab3569f4

- If number is negative, it cannot be less than FFE0000000, 
  and if number is positive, it cannot be greater than 1FFFFFFF.

...

所以你的论点(“FFF0FFFFFF”)超出了范围。

示例C#代码

private static String Hex2Oct(String value) {
  // Assuming that given value is short enough to be represented as Int64
  return Convert.ToString(Convert.ToInt64(value, 16), 8);
}
...
Console.Write(Hex2Oct("FFF0FFFFFF")); // 17776077777777