Solved: convert strings’s byte array to big integer and perform functions in any language

Question:

I want to convert String’s byte array to BigInteger and vis-versa.
I’m able to do this for some language specifically. For example:-
in java: new BigInteger("ab".getBytes())
and in dart: _convertBytesToBigInt(Uint8List.fromList(Utf8Encoder().convert('ab')))
where _convertBytesToBigInt() method is from dartlang sdk’s github issue discussion (here and here).
I tried coping the same code from dart to java:
and this don’t work when I try to perform simple multiplication/division in java (but it works in flutter however)
I tried copying Java’s BigInteger class and it’s toByteArray() method but again, it don’t work with dart properly.
These methods works normally if I try without multiplication/division, so only possible thing is, they both multiply/divide in different way if I’m not wrong.
Is there ANY solution for this? So that I can turn byte arr to BigInteger in ANY language (specifically popular ones like Java, Dart/flutter, Rust, Python, JS, etc).
NOTE:
Following are the methods which I used in dart and java respectively.
Side note regarding writeBigInt: just use Number#byteValue() instead of toString() and parseInt().
Udate
_convertBytesToBigInt() assumes the bytes to be given in big-endian whereas writeBigInt writes little-endian. Here’s a corrected version for that, too:

byte[] writeBigInt(BigInteger number) {
// Not handling negative numbers. Decide how you want to do that.
int bytes = (number.bitLength() + 7) >> 3;
BigInteger b256 = BigInteger.valueOf(256);
byte[] result = new byte[bytes];
for (int i = 0; i < bytes; i++) { result[bytes-1-i] = number.remainder(b256).byteValue(); number = number.shiftRight(8); } return result; } [/code]

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com