public void cCalc() {
oct1 = oct1 & sm1;
oct2 = oct2 & sm2;
oct3 = oct3 & sm3;
oct4 = oct4 & sm4;
String binString;
binString = Integer.toBinaryString(sm1) + Integer.toBinaryString(sm2) +
Integer.toBinaryString(sm3) + Integer.toBinaryString(sm4);
int count = 0;
for (int loop = 0; loop < binString.length(); loop++) {
if (binString.charAt(loop) == '1') {
count++;
}
}
int hostBits = 32 - count;
int hostsAvailable = (int) Math.pow(2, hostBits) - 2; //2^n - 2
int extraBits = count - 24;
int networksAvailable = (int) Math.pow(2, extraBits);
System.out.println("Hosts per Network = " + hostsAvailable);
System.out.println("Number of Networks = " + networksAvailable);
String finalCalc = "";
for (int loop = 1; loop <= networksAvailable; loop++) {
//ID
finalCalc = finalCalc + " Network ID: " + oct1 + "." + oct2 + "." + oct3 + "." + oct4;
//Start
oct4 = oct4 + 1;
finalCalc = finalCalc + "\n Subnet Range(s): " + oct1 + "." + oct2 + "." + oct3 + "." + oct4 + " to ";
//End
oct4 = oct4 + hostsAvailable - 1;
finalCalc = finalCalc + " " + oct1 + "." + oct2 + "." + oct3 + "." + oct4;
//BroadcastAddress
oct4 = oct4 + 1;
finalCalc = finalCalc + "\n Broadcast address: " + oct1 + "." + oct2 + "." + oct3 + "." + oct4;
//For next ID
oct4 = oct4 + 1;
finalCalc = finalCalc + "\n";
setResult(finalCalc);
}
}
这是我在子网范围计算器应用程序中的c类ip地址范围计算方法-虽然我了解c类所需的计算,但a类和b类的计算对我来说似乎是不可能的。
我怎么开始计算a和b级呢?在过去一周左右的时间里,我一直在用谷歌搜索和反复试验,但我似乎无法理解这一点。
任何建议或信息都会非常棒。
(请原谅我的代码可能不好,我是java的初学者)
暂无答案!
目前还没有任何答案,快来回答吧!