Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

from byteArray to bigInteger

Tags:

java

integer

how to convert a byteArray to bigInteger? it's important to say than my bytearray is not the ordinay byte[].. its a class in my project. basically i have an array of 256 bytes and i need to represent it as BigInteger in order to perform a calculation .

the code looks like this:

//this is how i get my information in byteArray

  ByteArray modulus = (ByteArray)inParamsList.getParameterType("modulus");

//this is the line that i get an exception for. it happens because the "toString" doesn't actully converts it to string

  BigInteger modulusInBig = new BigInteger(modulus.toString());

i would be very happy to get some answers! i lookes all over the internet already...

like image 229
user1584314 Avatar asked Nov 03 '22 12:11

user1584314


1 Answers

Modify your ByteArray class to provide a toArrayByte() method, returning byte[] then:

BigInteger modulusInBig = new BigInteger(modulus.toArrayByte());
like image 134
weston Avatar answered Nov 12 '22 12:11

weston