1
2package org.arpit.java2blog;
3
4import java.math.BigInteger;
5
6public class StringToBigIntegerMain {
7
8 public static void main(String[] args) {
9
10 String str="45";
11 BigInteger bigIntegerStr=new BigInteger(str);
12 System.out.println("Converted String to BigInteger: "+bigIntegerStr);
13 }
14}
15
16
1String foo = "some text";
2byte[] fooBytes = foo.getBytes();
3BigInteger bi = new BigInteger(fooBytes);
1package com.mkyong;
2
3import java.math.BigInteger;
4
5public class JavaExample {
6
7 public static void main(String[] args) {
8
9 int n = 100;
10 System.out.println(n);
11
12 // convert int to Integer
13 Integer integer = Integer.valueOf(n);
14 System.out.println(integer);
15
16 // convert int to BigInteger
17 BigInteger bigInteger = BigInteger.valueOf(n);
18 System.out.println(bigInteger);
19
20 // convert Integer to BigInteger
21 //BigInteger bigInteger2 = BigInteger.valueOf(integer); // works
22 BigInteger bigInteger2 = BigInteger.valueOf(integer.intValue());
23 System.out.println(bigInteger2);
24
25 }
26
27}
1public BigInteger toBigInteger(String foo)
2{
3 return new BigInteger(foo.getBytes());
4}
5
6public String fromBigInteger(BigInteger bar)
7{
8 return new String(bar.toByteArray());
9}