簡體   English   中英

針對虛擬地址使用biginteger for Java程序

[英]using biginteger for java program regarding virtual addresses

可能是由於我對biginteger的使用有限而造成的誤解,但是我有一個程序需要獲取用戶輸入的頁面大小和虛擬地址,並計算偏移量和虛擬頁面。 我可以進行計算,沒問題,但是在比較輸入的iteger時,虛擬地址的必要值(4294967295)超出范圍。 我試圖將這個數字聲明為一個大整數,但是相同的運算符似乎無效。 我是否必須忘記零,而只是想辦法說輸入小於或等於該數字? 這是代碼:

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