0

I'm trying to write a Java code equivalent of the below Javascript code (convert JS to Java)

JavaScript Code (it reverses an Array and converts to/forms a Big Integer to the base decimal):

var decimal=bigInt.fromArray(binArr.reverse(), 2);

Java code I tried:

BigInteger bigint1=new BigInteger(Collections.reverse(Arrays.asList(a)),2); 

(using a syntax I saw online,but I couldnt proceed anything beyond that)

Could you provide some inputs on this?

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
SidTechs1
  • 67
  • 4
  • 12
  • *(using a syntax I saw online...* There's nothing wrong with learning from online sources but sounds like you can't proceed past copy&paste solutions. Perhaps you can explain in little more detail what is wrong with the the java code you tried – President James K. Polk Mar 05 '19 at 22:32
  • Does the Javascript array have a different endianness from the array a big integer expects? Is this the same for your Java array? You only have to reverse the array if it has the wrong endianness. And it should be easy to find code that can reverse an array. FWIW, is this a byte array or what exactly? – Rudy Velthuis Mar 06 '19 at 13:03
  • @JamesKPolk:Meant I saw a syntax online,which is nothing wrong since I am learning new things, but couldnt get the complete working solution with the code I tried based on what I saw .Thank. – SidTechs1 Mar 06 '19 at 15:10
  • @RudyVelthuis: I am reversing the Array because of my program logic, just wanted to clarify its not related to me trying to convert the datatypes . I'm able to reverse the array but facing difficulty in converting the reversed array to a single BigInteger variable. Any inputs on that would be helpful pls. – SidTechs1 Mar 06 '19 at 15:12

0 Answers0