vba 如何将 14 位十六进制转换为十进制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20996046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 01:16:00  来源:igfitidea点击:

How to convert 14 bit Hex to Decimal

excelexcel-vbaexcel-2013vba

提问by Leigh

I need to be able to convert 047C1BEA3A2480into Decimal. This should convert to 1262359242482816. I have a large amount of hex numbers that need converting so would need a formula or VB script.

我需要能够转换047C1BEA3A2480为十进制。这应该转换为1262359242482816. 我有大量需要转换的十六进制数字,因此需要一个公式或 VB 脚本。

I have tried some things including a VB Module, however with this I need to prefix the number with 0X but then gives me a decimal number that is out by 4.

我尝试了一些东西,包括一个 VB 模块,但是我需要在数字前加上 0X 前缀,然后给我一个 4 的十进制数。

Any ideas would be great.

任何想法都会很棒。

回答by Siddharth Rout

Use the inbuilt CDecfunction

使用内置CDec函数

Debug.Print CDec("&H" & "047C1BEA3A2480")

This will give you 1262359242482816

这会给你 1262359242482816

Screenshot

截屏

enter image description here

在此处输入图片说明

回答by Robert Co

Split into 2 7-digits and use the HEX2DEC function. Unfortunately, Excel cannot handle that big a number, so it is rounding when you put it back in Excel. For exmaple, try to paste the decimal version into Excel. But if you want the formula anyway.

拆分为 2 个 7 位数字并使用 HEX2DEC 函数。不幸的是,Excel 无法处理这么大的数字,所以当你把它放回 Excel 时它会四舍五入。例如,尝试将十进制版本粘贴到 Excel 中。但是,如果您无论如何都想要公式。

=HEX2DEC(LEFT(A4,7))*16^7+HEX2DEC(RIGHT(A4,7))

Otherwise, use Siddarth's solution and put it in Excel as Text.

否则,使用 Siddarth 的解决方案并将其作为文本放入 Excel。