首页 > 解决方案 > C# 中是否有 Python 的 binascii.b2a_hex 的等效函数?

问题描述

我正在尝试从使用binascii.b2a_hex. 我不知道任何 C# 等价物。C# 中的什么函数会给我相同的结果?

我在网上查了一下,有没有人有同样的问题,但还没有找到人。我什至寻找第三方库。我确实让我的应用程序从 Python 脚本中获取结果,但我想真实地移植代码。

def send_withlen(self, data, log = True) :
    lengthstr = struct.pack(">L", len(data))
    if log :
        logging.debug(str(self.address) + ": Sent data with length - " + binascii.b2a_hex(lengthstr) + " " + binascii.b2a_hex(data))
    totaldata = lengthstr + data
    totalsent = 0
    while totalsent < len(totaldata) :
        sent = self.send(totaldata, False)
        if sent == 0:
            raise RuntimeError, "socket connection broken"
        totalsent = totalsent + sent

以下是一些记录器调试行的示例,显示了函数输出的格式:

2019-10-15 00:03:14,220 root         DEBUG    ('192.168.0.17', 59176): Sent data with length - 0000010a 01500a010000000000000400040000000c0000001200000004000400000005000000120000000400040000000000000003000000040004000000060000000e00000004000400000004000000110000000400040000000a000000110000000400040000000b000000626172000400040000000f0000000e0100000400040000000200000057000000040004000000030000000000000004000400000009000000666f6f0004000400000007000000626f6f000400040000000d000000666f6f0004000400000008000000fb0000000400240000000e000000015024000000000000000300040000006361631a00000003000400000063617308000000040004000000010000000e000000

2019-10-15 00:03:14,292 dirsrv       INFO     ('192.168.0.17', 59178): Sending out list of content list servers
2019-10-15 00:03:14,293 root         DEBUG    ('192.168.0.17', 59178): Sent data with length - 00000008 0001c0a800119d69

标签: c#pythonunicode

解决方案


推荐阅读