Here you can find the source of int2buff(int n)
Parameter | Description |
---|---|
n | number |
public static byte[] int2buff(int n)
//package com.java2s; /**// w ww . j a v a 2 s. c om * Copyright (C) 2008 Happy Fish / YuQing * * FastDHT Java Client may be copied only under the terms of the GNU Lesser * General Public License (LGPL). * Please visit the FastDHT Home Page http://fastdht.csource.org/ for more detail. **/ public class Main { /** * int convert to buff (big-endian) * @param n number * @return 4 bytes buff */ public static byte[] int2buff(int n) { byte[] bs; bs = new byte[4]; bs[0] = (byte) ((n >> 24) & 0xFF); bs[1] = (byte) ((n >> 16) & 0xFF); bs[2] = (byte) ((n >> 8) & 0xFF); bs[3] = (byte) (n & 0xFF); return bs; } /** * int convert to buff (big-endian) * @param n number * @param bs byte buff * @param offset buff start index */ public static void int2buff(int n, byte[] bs, int offset) { bs[offset] = (byte) ((n >> 24) & 0xFF); bs[offset + 1] = (byte) ((n >> 16) & 0xFF); bs[offset + 2] = (byte) ((n >> 8) & 0xFF); bs[offset + 3] = (byte) (n & 0xFF); return; } }