Here you can find the source of intToNumericFormat(int src)
Parameter | Description |
---|---|
src | integer representation of the IPv4 address |
public static byte[] intToNumericFormat(int src)
//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; } }