5

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...

7
  • 3
    did you check what does modulus.toString() produce? Commented Nov 4, 2012 at 15:57
  • 4
    Can we see the ByteArray class? Commented Nov 4, 2012 at 15:58
  • How should the bytes in the array be interpreted for conversion to a number? Commented Nov 4, 2012 at 16:00
  • @MattBall that is already defined by the constuctors of BigInteger. Commented Nov 4, 2012 at 16:23
  • @weston not necessarily. It depends on how the OP is currently representing the number in a byte array. There is more than one way to interpret a sequence of bits. Commented Nov 4, 2012 at 16:27

1 Answer 1

2

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

BigInteger modulusInBig = new BigInteger(modulus.toArrayByte()); 
Sign up to request clarification or add additional context in comments.

2 Comments

you wrote: "Modify your ByteArray class to provide a toArrayByte() method, returning byte[]"... this it exacly my problem.. i'm not sure how to do that..
Then we need to see your ByteArray class. Lots of people have asked for that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.