Ejemplo 1: transformer un string en Biginteger java
package org.arpit.java2blog;
import java.math.BigInteger;
public class StringToBigIntegerMain {
public static void main(String[] args) {
String str="45";
BigInteger bigIntegerStr=new BigInteger(str);
System.out.println("Converted String to BigInteger: "+bigIntegerStr);
}
}
Ejemplo 2: transformer un string en Biginteger java
String foo = "some text";
byte[] fooBytes = foo.getBytes();
BigInteger bi = new BigInteger(fooBytes);
Ejemplo 3: transformer un string en Biginteger java
package com.mkyong;
import java.math.BigInteger;
public class JavaExample {
public static void main(String[] args) {
int n = 100;
System.out.println(n);
// convert int to Integer
Integer integer = Integer.valueOf(n);
System.out.println(integer);
// convert int to BigInteger
BigInteger bigInteger = BigInteger.valueOf(n);
System.out.println(bigInteger);
// convert Integer to BigInteger
//BigInteger bigInteger2 = BigInteger.valueOf(integer); // works
BigInteger bigInteger2 = BigInteger.valueOf(integer.intValue());
System.out.println(bigInteger2);
}
}
Ejemplo 4: transformer un string en Biginteger java
public BigInteger toBigInteger(String foo)
{
return new BigInteger(foo.getBytes());
}
public String fromBigInteger(BigInteger bar)
{
return new String(bar.toByteArray());
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)