Java BigInteger vs Mono .net BigInteger

僤鯓⒐⒋嵵緔 提交于 2019-11-29 14:42:10

From the docs for java.math.BigInteger(byte[]):

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.

From the docs for System.Numerics.BigInteger(byte[]):

The individual bytes in the value array should be in little-endian order, from lowest-order byte to highest-order byte.

So you might want to just try reversing the input bytes for one of the values you've got - it's not clear which set you should reverse, as we don't know what values you're trying to represent. I would suggest adding diagnostics of just printing out the normal decimal representation immediately after construction in each case - if those aren't the same, the rest of the code is irrelevant.

I solved my problem by adding 0 bit at the begining of inputBytes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!