简体   繁体   中英

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. 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. 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进行比较,请参阅此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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