c# java >>>,相同的字节数组=> 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值