1) The IP address and subnet mask are given. You need to calculate the network address: implement the getNetAddress method.
Use the bitwise AND operator.
Example:
IP address: 11000000 10101000 00000001 00000010 (192.168.1.2)
Subnet mask: 11111111 11111111 11111110 00000000 (255.255.254.0)
Determine the network address
- 24
Locked
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Justin Smith
6 December 2021, 03:17
Tough task but very interesting. This topic is definitely not how I expected to start a section called "Multithreading".
0
SunMind
5 January 2021, 21:57
Integer.toBinaryString(256 + (int) aByte);
Why need to make addition here?
0
Andrei
9 March 2021, 15:09
I am assuming because byte is up to 127 (inclusive) so you would lose some numbers from 192 but I don't understand the use of 256 here. Why 256 and not any other number?
0
Andrei
9 March 2021, 15:33
Please check Guada's answer here: https://codegym.cc/help/14585
+1
Justin Smith
6 December 2021, 03:17
It's filling the first 8 digits with 1s so that leading 0s aren't cut off. For example, if your byte is: 00000101, using toBinaryString will create "101" as the string. To pass validation, all 8 digits must be included. 256 + (int) aByte causes the toBinaryString to output 1111111100000101, so the 0s aren't lost.
It's a lot simpler than the method I used, which use String.format and "%8s" to force it to be at least 8 characters long, then replaceAll to replace the spaces with 0s.
0
yehuda b
22 December 2020, 13:54
To get a string representation of the binary digits of each byte, see https://stackoverflow.com/questions/12310017/how-to-convert-a-byte-to-its-binary-string-representation
+1