Same byte array => Different BigInteger value in Java and C #

I have Java and C # code as below:

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);

As you can see, both arrays are the same. But why does the BigInteger constructor in Java return a different value than in C #?

Java value for byteArrayAsBigInt:

435547623972009042387221878687981899647773248766318257271173050301525056529400623692496442046820

C # value for ArrayAsBigInt byte:

836240090191738952707023426454050812020217962491637996803829702297801636146665723913243623568180

Does anyone have an idea?

+4
source share
1 answer

The answer is that Java assumes a large ordinary order, but C # uses Little Endian.

From the Java documentation:

public BigInteger (byte [] val) , BigInteger BigInteger. , big-endian: .

#:

BigInteger ( []) : System.Byte [] -endian .

+1

Source: https://habr.com/ru/post/1569558/


All Articles