Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的java ByteBuffer getInt? byte[]obyterarray=新字节[4]; String str=“测试”; 试一试{ obyterarray=str.getBytes(“UTF-8”); }catch(java.io.UnsupportedEncodingException e){ } int vi1=ByteBuffer.wrap(obyteArray.getInt(); 系统输出打印项次(vi1);_Java_Python_Byte - Fatal编程技术网

python中的java ByteBuffer getInt? byte[]obyterarray=新字节[4]; String str=“测试”; 试一试{ obyterarray=str.getBytes(“UTF-8”); }catch(java.io.UnsupportedEncodingException e){ } int vi1=ByteBuffer.wrap(obyteArray.getInt(); 系统输出打印项次(vi1);

python中的java ByteBuffer getInt? byte[]obyterarray=新字节[4]; String str=“测试”; 试一试{ obyterarray=str.getBytes(“UTF-8”); }catch(java.io.UnsupportedEncodingException e){ } int vi1=ByteBuffer.wrap(obyteArray.getInt(); 系统输出打印项次(vi1);,java,python,byte,Java,Python,Byte,返回1952805748 但是在py中 elements=b“测试” 值=字节数组(元素) 打印(int.from_字节(值'big')) 返回32762643847147111 byte[] obyteArray = new byte[4]; String str = "testing"; try{ obyteArray = str.getBytes("UTF-8"); 在上面的语句之后,原始的oByteArr

返回1952805748

但是在py中

elements=b“测试”
值=字节数组(元素)
打印(int.from_字节(值'big'))
返回32762643847147111

    byte[] obyteArray = new byte[4];
    String str = "testing";
    try{
        obyteArray = str.getBytes("UTF-8");
在上面的语句之后,原始的
oByteArray
被丢弃,而
oByteArray
是对不同7字节数组的引用

    }catch(java.io.UnsupportedEncodingException e){    
    }
    int vi1 = ByteBuffer.wrap(obyteArray).getInt();
vi1
现在是前4个字节(
'test'
),被重新解释为
int

    System.out.println(vi1);

这就是结果不同的原因。

不太清楚你想要实现什么。我已经在我的回答中解释了为什么你没有得到相同的结果,但是如果你需要更多的帮助,我们需要知道你试图解决的问题。Java和Python是非常不同的语言。例如,Python支持任意精度整数,而Java要求您使用
biginger