使用biginteger进行关于虚拟地址的java程序

时间:2015-06-05 16:20:57

标签: java virtual biginteger

由于我对biginteger的使用有限,我可能会误解,但我有一个程序需要用户输入页面大小和虚拟地址,并计算偏移量和虚拟页面。我可以毫无问题地进行计算,但是当比较输入的迭代器时,虚拟地址的必要值(4294967295)超出范围。我试图将这个数字声明为一个大的int,但是相同的运算符似乎不起作用。我是否必须忘记零,只是找到一种方法来说输入小于或等于这个数字?这是代码:

public class VAddress {

public static void main(String args[]){

    BigInteger max = new BigInteger("4294967295"); 

    Scanner PAGEinput = new Scanner(System.in);
    Scanner ADDinput = new Scanner(System.in);

      System.out.println("Please Enter the system page size (between 512 and 16384):");
    int page = PAGEinput.nextInt();

    System.out.println("Please Enter the Virtual Address: ");
    int address = ADDinput.nextInt();

    if(page >= 512 && page <= 16384){
        if( address >= 0 && address <= max){

        }
       }



     }

 }

2 个答案:

答案 0 :(得分:1)

BigInteger address = new BigInteger(address);
if(page >= 512 && page <= 16384){
    if(address.compareTo(new BigInteger("0"))>=0 && address.compareTo(max)<=0){

    }
}

答案 1 :(得分:0)

您还需要将整数setup.exe转换为BigInteger,以便将其与max进行比较,请参阅this question