3

用 Python 重写 Java 代码同样的位移取反操作, 遇到问题, 请帮忙看看

 3 years ago
source link: https://www.v2ex.com/t/802185
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Python

用 Python 重写 Java 代码同样的位移取反操作, 遇到问题, 请帮忙看看

  l4ever · 15 小时 30 分钟前 · 563 次点击
inputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(srcFile), 1024 * 8));
            byte[] vb = new byte[7];

            if (inputStream.read(vb, 0, 6) > 0) {
                for (int i = 0; i < 6; i++) {
                    vb[i] = (byte) ((0xFF & vb[i]) >> 4 | (0xFF & vb[i]) << 4);
                    vb[i] = (byte) ~vb[i];
                }
                vb[6] = 0;
            }

            version = new String(vb, 0, vb.length - 1);
def decode():
    version_byte = b'\x9a\xac\x1d\xfc\xfc\xfc'
    result_bytes = bytearray()

    for i, value in enumerate(version_byte):
        version_int = value
        version_int = (version_int >> 4 | version_int << 4)
        version_int = ~version_int
        print(f'{version_int} {version_int}')
        result_bytes.insert(i, version_int)

帮忙看看 java 的代码, 我用 python 实现不了同样的功能


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK