/* * 0=Class A * 1=Class B * 2=Class C * 3=Class D * 4=Class E * -1=error */ public int getNetworkClass() { // Test Class A: first bit=0 if (!IPTool.isBitSet(this.get1Byte(), 8)) { return(0); } // Test Class B: first 2bit=10 else if (!IPTool.isBitSet(this.get1Byte(), 7)) { return(1); } // Test Class C: first 3bit=110 else if (!IPTool.isBitSet(this.get1Byte(), 6)) { return(2); } // Test Class D: first 4bit=1110 else if (!IPTool.isBitSet(this.get1Byte(), 5)) { return(3); } // Test Class E: first 4bit=1111 ( = all other) // else if (!IPTool.isBitSet(this.get1Byte(),8)) return 4; else { return(4); } /* * // Test Class A: first bit=0 * if ((this.get1Byte() | (byte)0x7f) == (byte)0x7f) return 0; * // Test Class B: first 2bit=10 * if ((this.get1Byte() | 0xbf) == 0xbf) return 1; * // Test Class C: first 3bit=110 * if ((this.get1Byte() | 0xdf) == 0xdf) return 2; * // Test Class D: first 4bit=1110 * if ((this.get1Byte() | 0xef) == 0xef) return 3; * // Test Class E: first 4bit=1111 * if ((this.get1Byte() & 0xf0) == 0xf0) return 4; * return -1; */ }