爪哇/Python:转换int到字节[]数组

2024-04-25 21:50:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将一些Python代码移植到Java中,好吧,已经做了很多工作,但我还是被这个函数卡住了。它应该将int转换为byte[]数组。在

我知道if语句类似于? :,但我需要一些帮助。在

def adjustId(self, _id):
        _id = format(_id, 'x')
        zfiller = len(_id) if len(_id) % 2 == 0 else len(_id) + 1
        _id = _id.zfill(zfiller if zfiller > 6 else 6)
        # if len(_id) % 2:
        #     _id = "0" + _id
        return binascii.unhexlify(_id)

所以我的问题是:如何将这些代码转换成java?在


Tags: 函数代码selfidlenifdef数组