简体   繁体   English

针对虚拟地址使用biginteger for Java程序

[英]using biginteger for java program regarding virtual addresses

Maybe I'm misunderstanding due to my limited use of biginteger, but I have a program that needs to take user input for page size and virtual address and calculate offset and virtual page. 可能是由于我对biginteger的使用有限而造成的误解,但是我有一个程序需要获取用户输入的页面大小和虚拟地址,并计算偏移量和虚拟页面。 I can do the calculation no problem, but when comparing itegers for the input, the necessary value of virtual address ( 4294967295)is out of range. 我可以进行计算,没问题,但是在比较输入的iteger时,虚拟地址的必要值(4294967295)超出范围。 I tried to declare this number as a big int but the same operators don't seem to work. 我试图将这个数字声明为一个大整数,但是相同的运算符似乎无效。 Do I have to forget the zero and just find a way to say the input is less than or equal to this number? 我是否必须忘记零,而只是想办法说输入小于或等于该数字? Here is the code: 这是代码:

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){

        }
       }



     }

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

    }
}

您还需要将整数address转换为BigInteger,以便可以将其与max进行比较,请参阅此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM