c# java gt;gt;gt;,相同的字节数组=gt; Java和C#中的不同BigInteger值
byte[] byteArray = {
52, 51, 102, 100, 55, 48, 48, 48, 57, 97, 57, 55, 97, 55, 100, 51, 49, 49, 99, 53, 54, 52, 52,
48, 52, 55, 99, 99, 99, 55, 48, 48, 102, 56, 100, 48, 56, 97, 57, 100
};
BigInteger byteArrayAsBigInt = new BigInteger(byteArray);
正如您所看到的,兩個陣列都是相同的.但是為什么Java中的BigInteger構造函數返回的值不同于C#中的值?
byteArrayAsBigInt的Java值:
435547623972009042387221878687981899647773248766318257271173050301525056529400623692496442046820
byteArrayAsBigInt的C#值:
836240090191738952707023426454050812020217962491637996803829702297801636146665723913243623568180
任何人都有任何想法?
解決方法:
答案是在Java Big Endian中假設順序,但在C#中使用Little Endian.
從Java文檔:
public BigInteger(byte[] val) Translates a byte array containing the
two’s-complement binary representation of a BigInteger into a
BigInteger. The input array is assumed to be in big-endian byte-order:
the most significant byte is in the zeroth element.
來自C#文檔:
BigInteger Constructor (Byte[])
Type: System.Byte[]
An array of byte values in little-endian order.
標簽:c,java
來源: https://codeday.me/bug/20190708/1402419.html
總結
以上是生活随笔為你收集整理的c# java gt;gt;gt;,相同的字节数组=gt; Java和C#中的不同BigInteger值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql+where+且,MySQL
- 下一篇: matlab中句点,matlab入门学习