Java Integer to intToNumericFormat(int src)

Here you can find the source of intToNumericFormat(int src)

Description

Converts the internal integer representation of an IPv4 into a binary address.

License

Apache License

Parameter

Parameter Description
src integer representation of the IPv4 address

Return

a byte array representing an IPv4 numeric address

Declaration

public static byte[] intToNumericFormat(int src) 

Method Source Code

//package com.java2s;
/* //from  w  w  w. ja v  a2  s  .c om
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */

public class Main {
    public static final int INADDRSZ = 4;

    /**
     * Converts the internal integer representation of an IPv4 into a binary address.
     * 
     * @param src
     *            integer representation of the IPv4 address
     * @return a byte array representing an IPv4 numeric address
     */
    public static byte[] intToNumericFormat(int src) {
        byte[] addr = new byte[INADDRSZ];

        addr[0] = (byte) ((src >>> 24) & 0xFF);
        addr[1] = (byte) ((src >>> 16) & 0xFF);
        addr[2] = (byte) ((src >>> 8) & 0xFF);
        addr[3] = (byte) (src & 0xFF);

        return addr;
    }
}

Related

  1. intToLittleEndian(int value)
  2. intToMCInts(int i)
  3. intToMmss(int ns)
  4. intToNetworkByteOrder(int num, byte[] buf, int start, int count)
  5. intToNetworkByteOrder(int num, int count)
  6. intToOctal(int value)
  7. IntToOctString(final int value)
  8. intToOneByte(int i)
  9. intToOneByte(int value)