问题1640--IP ADDRESS ANALYSIS

1640: IP ADDRESS ANALYSIS

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 64 MB

题目描述

    Determine the network prefix and host suffix for an IPV4 address

Version 4 of the Internet Protocol (IP) defines class A, class B, and class C addresses. The following table shows an example of each of the three classes of addresses. In the familiar "dotted decimal" notation, each of the four numerical fields of the address is a non-negative integer not exceeding 255. In the binary form, each field of the address is expressed in base 2 as an 8-bit "octet". For example, the number 200, written as a sum of powers of 2, equals 128+64+8 = 2^7 + 2^6 + 2^3 = 11001000 binary.
    ClassIP address in "dotted decimal" notationIP address in binary
    A64.200.128.301000000.11001000.10000000.00000011
    B160.200.128.310100000.11001000.10000000.00000011
    C202.200.128.311001010.11001000.10000000.00000011

Definitions:

    Class A address: The leftmost bit of the leftmost field of the binary representation is 0.

    Class B address: The leftmost two bits of the leftmost field of the binary representation are 10.

    Class C address: The leftmost three bits of the leftmost field of the binary representation are 110.

Components of a Class A address:

The leftmost bit is used only to identify the type of address, therefore it is not part of the actual address. The remaining bits of the leftmost field (in the above example, 1000000) constitute the network prefix (which identifies a particular subnet within the Internet). The remaining fields (11001000.10000000.00000011) are concatenated to form the host suffix (which identifies a particular computer within a subnet).

Therefore, in the above example,

    Network prefix = 1000000 binary = 64 decimal
    Host Suffix = 110010001000000000000011 binary = 13139971 decimal

Components of a Class B address:

The leftmost two bits are used only to identify the type of address, therefore they are not part of the actual address. The remaining bits of the leftmost field (in the above example, 100000), concatenated with the second-leftmost field (11001000) constitute the network prefix. The remaining fields (10000000.00000011) are concatenated to form the host suffix.

Therefore, in the above example,

    Network prefix = 10000011001000 binary = 8392 decimal
    Host Suffix = 1000000000000011 binary = 32771 decimal

Components of a Class C address:

The leftmost three bits are used only to identify the type of address, therefore they are not part of the actual address. The remaining bits of the leftmost field (in the above example, 01010), concatenated with the second- and third-leftmost fields (11001000.10000000) constitute the network prefix. The remaining field (00000011) forms the host suffix.

Therefore, in the above example,

    Network prefix = 010101100100010000000 binary = 706688
    Host Suffix = 00000011 binary = 3

输入

One or more IP-addresses in dotted decimal form, 1 Each line of the input will contain exactly one IP address. 2 There will be no leading, trailing, or embedded spaces or tabs. 3 Each IP address will contain four numerical fields. Adjacent fields will be separated by one period ("dot"). 4 Each numerical field will be a non-negative integer, not exceeding 255.

输出

Each line of input will give rise to one line of output, containing the network prefix and host suffix, in the format illustrated by the following example (which comes from the above input example). Note, in particular, that each numerical quantity is right-justified in a field of width 9 following the equals sign. Each equals sign is also preceded by one blank space, and the word "suffix" is preceded by two blank spaces.

样例输入 Copy

<ul><tt><pre>
<font color=red>       column   111111111122222222223</font>
<font color=red>       123456789012345678901234567890</font>
<font color=red>line 1:</font>64.200.128.3<font color=red>[EOL]</font>
<font color=red>     2:</font>160.200.128.3<font color=red>[EOL]</font>
<font color=red>     3:</font>202.200.128.3<font color=red>[EOL]</font>
<font color=red>     4:</font>127.255.255.255<font color=red>[EOL]</font>
<font color=red>      :</font><font color=red>[EOF]</font>
</pre></tt></ul>

样例输出 Copy

<ul><tt><pre>
<font color=red>       column   111111111122222222223333333333</font>
<font color=red>       123456789012345678901234567890123456789</font>
<font color=red>line 1:</font>Program 2 by team 0<font color=red>[EOL]</font>
<font color=red>     2:</font>prefix =       64  suffix = 13139971<font color=red>[EOL]</font>
<font color=red>     3:</font>prefix =     8392  suffix =    32771<font color=red>[EOL]</font>
<font color=red>     4:</font>prefix =   706688  suffix =        3<font color=red>[EOL]</font>
<font color=red>     5:</font>prefix =      127  suffix = 16777215<font color=red>[EOL]</font>
<font color=red>     6:</font>End of program 2 by team 0<font color=red>[EOL]</font>
<font color=red>      :</font><font color=red>[EOF]</font>
</pre></tt></ul>