gpt4 book ai didi

excel - 在 Excel 中将十六进制转换为 base64

转载 作者:行者123 更新时间:2023-12-04 22:28:14 26 4
gpt4 key购买 nike

我知道已经存在同名主题 Convert a hex string to base64 in an excel function但是,我没有收到与线程中提供的 VBA 所期望的相同的结果。我正在使用这个网站,它提供了正确的答案 https://cryptii.com/pipes/base64-to-hex

看起来 Hex2Base64 提供的结果中有 12 个不必要的字符。如何让它像网站一样工作?

我知道有一个简单的解决方案可以输入另一个单元格,例如:=LEFT(cell;20)但是如何使用当前的 VBA 来制作呢?

所以我有:

十六进制:01 00 00 00 05 00 00 00 00 E3 07 04 00 0F 00
在网站上我收到 BASE64:AQAAAAUAAAAA4wcEAA8A
enter image description here

通过提供的解决方案,在已经存在的线程中,我收到 BASE64:AQAAAAUAAAAA4wcEAA8AAAAAAAAAAA==

Function Hex2Base64(byVal strHex)
Dim arrBytes
If Len(strHex) Mod 2 <> 0 Then
strHex = Left(strHex, Len(strHex) - 1) & "0" & Right(strHex, 1)
End If
With CreateObject("Microsoft.XMLDOM").createElement("objNode")
.DataType = "bin.hex"
.Text = strHex
arrBytes = .nodeTypedValue
End With
With CreateObject("Microsoft.XMLDOM").createElement("objNode")
.DataType = "bin.base64"
.nodeTypedValue = arrBytes
Hex2Base64 = .Text
End With
End Function

最佳答案

问题在于输入参数 - 带空格的十六进制字符串。删除空格会产生预期的结果:

Debug.Print Hex2Base64(Replace("01 00 00 00 05 00 00 00 00 E3 07 04 00 0F 00", " ",""))

关于excel - 在 Excel 中将十六进制转换为 base64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55705506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com