- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
在我的公司有一个用python写的系统,我想用golang重新实现它。
Python binascii.unhexlify
看起来很复杂,我不知道在 go 中实现它很热。
最佳答案
binascii.unhexlify
方法很简单。它只是从十六进制转换为二进制。每两个十六进制数字是一个 8 位字节(256 个可能的值)。这是我的代码
func unhexlify(str string) []byte {
res := make([]byte, 0)
for i := 0; i < len(str); i+=2 {
x, _ := strconv.ParseInt(str[i:i+2], 16, 32)
res = append(res, byte(x))
}
return res
}
我应该使用图书馆
func ExampleDecodeString() {
const s = "48656c6c6f20476f7068657221"
decoded, err := hex.DecodeString(s)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", decoded)
// Output:
// Hello Gopher!
}
关于python - 去如何实现python binascii.unhexlify方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55699760/
每当程序打开文件时,它都会将该文件视为二进制数据。它将其转换为更高级的解释语言,即八进制、十六进制、ascii 等。在这种情况下,它在左侧 Pane 中显示十六进制,在右侧 Pane 中显示 ansi
是否有类似 Python 的 unhexlify 用于 objc/cocoa 的东西? >>> from binascii import unhexlify>>> help(unhexlify)Hel
所以我使用 this SO answer 中的代码创建2路字母数字加密函数。 基本上,函数如下所示: from Crypto import Random from Crypto.Cipher impo
我正在尝试将 ASCII 字符串来回转换为其二进制表示,如下所示。 s=chr(0)*15 + chr(0x01) bst = bin(int(binascii.hexlify(s), 16)) n
我想将 XY 坐标的 WKB 表示形式转换为 YX 格式。我使用的代码适用于 42 个字符的 WKB 字符串,但是当我在 50 个字符的字符串上使用它时,它会给出一个奇怪的 YX 输出。我正在运行 P
请帮忙...我正在尝试学习 C 类型转换。 此代码仅将一些十六进制字符转换为 1, 2, 3,效果很好。对于其他字符,也更改字符串或减少字符串长度,转换失败... 我将把代码放在下面...任何人都可以
这个问题在这里已经有了答案: 关闭 13 年前。 Possible Duplicate: How to convert hex to a byte array? 我正在 C# 中寻找一个 pytho
我的代码看起来有点像 module Lib where import Data.ByteString (ByteString) import Data.ByteString.Lazy (fromStr
我对Python不熟悉,需要从2.7移植到3.5。在 2.7 中: >>> unhexlify( '2FE2' )[0] '/' 在 3.5 中: >>> unhexlify( '2FE2' )[0]
我对此进行了广泛的搜索,但找不到解决此问题的帖子。我有一个简单的字符串,它是从 82001B014042 的调制解调器收到的。我想忽略 82001B01 的前面的 header 并解码十六进制数字 4
我是一名优秀的程序员,十分优秀!