V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Linxing
0.85D
V2EX  ›  问与答

一段 Java 代码 转换成 Python 代码的问题

  •  
  •   Linxing · Mar 12, 2018 · 1397 views
    This topic created in 2974 days ago, the information mentioned may be changed or developed.
    public static byte[] marshallInt(int num,int length) {
    byte[] byteStream = new byte[length];
    for (int i = 0; i < length; i++) {
    byteStream[i] = (byte) (num >>> ((length-1)*8 - i * 8));
    }
    return byteStream;
    }


    byte length[]=marshallInt(sendmsg.length(),2);


    ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
    baos1.write(length);
    baos1.write(sendmsg.getBytes());
    byte[] bufferOut = baos1.toByteArray();
    socketOut.write(bufferOut);

    Python 的字节数组要怎么整 环境是 Python2.7
    能力有限 搜了一圈 都没有想明白要怎么转换
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1281 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 16:52 · PVG 00:52 · LAX 09:52 · JFK 12:52
    ♥ Do have faith in what you're doing.