Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Split biginteger into digits and put them in an array  RSS feed

 
Chaturaka Gunatilaka
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I split biginteger into digits and put them in an array?
For an example...
BigInteger number=127363753964862826227912939336319393;
array[]={1,2,7,3,6,3,7,5,3,9,6,4,8,6,....,3};

Thank you.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could convert the value to a String and then convert each character of that String to an int (assuming you want the output to be an int array).

You could continually divide the number by 10 and add the remainder of each division into your array.

There are probably other ways as well
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!