Converts an int value to a byte[4] array.

@param v the value to be converted.

@return a byte[4] containing the value.
421136
public static byte[] intToRegisters(int v) {
        byte[] registers = new byte[4];
        registers[0] = (byte)(0xff & (v >> 24));
        registers[1] = (byte)(0xff & (v >> 16));
        registers[2] = (byte)(0xff & (v >> 8));
        registers[3] = (byte)(0xff & v);
        return registers;
    }
1278721
public static int varintSizeInBytes(long v) {
    if ((v & (0xffffffffffffffffL << 7)) == 0) return 1;
    if ((v & (0xffffffffffffffffL << 14)) == 0) return 2;
    if ((v & (0xffffffffffffffffL << 21)) == 0) return 3;
    if ((v & (0xffffffffffffffffL << 28)) == 0) return 4;
    if ((v & (0xffffffffffffffffL << 35)) == 0) return 5;
    if ((v & (0xffffffffffffffffL << 42)) == 0) return 6;
    if ((v & (0xffffffffffffffffL << 49)) == 0) return 7;
    if ((v & (0xffffffffffffffffL << 56)) == 0) return 8;
    if ((v & (0xffffffffffffffffL << 63)) == 0) return 9;
    return 10;
  }
277320
public static byte[] getBytes(long value) {
        return new byte[]{(byte) (value >> 56), (byte) (value >> 48), (byte) (value >> 40), (byte) (value >> 32),
                (byte) (value >> 24), (byte) (value >> 16), (byte) (value >> 8), (byte) value};
    }
1239757
public static byte[] getVariableByteUnsigned(int value) {
        if (value < 0) {
            throw new InvalidParameterException("negative value not allowed: " + value);
        } else if (value < 128) { // 2^7
            // encode the number in a single byte
            return new byte[]{(byte) value};
        } else if (value < 16384) { // 2^14
            // encode the number in two bytes
            return new byte[]{(byte) (value | 0x80), (byte) (value >> 7)};
        } else if (value < 2097152) { // 2^21
            // encode the number in three bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) (value >> 14)};
        } else if (value < 268435456) { // 2^28
            // encode the number in four bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) ((value >> 14) | 0x80),
                    (byte) (value >> 21)};
        } else {
            // encode the number in five bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) ((value >> 14) | 0x80),
                    (byte) ((value >> 21) | 0x80), (byte) (value >> 28)};
        }
    }
1024681
public static String longToHexBytes(final long v) {
    final long mask = 0XFFL;
    final StringBuilder sb = new StringBuilder();
    for (int i = 8; i-- > 0; ) {
      final String s = Long.toHexString((v >>> (i * 8)) & mask);
      sb.append(zeroPad(s, 2)).append(" ");
    }
    return sb.toString();
  }
990481
public static UByte[] ubyte_a(byte... values) {
        UByte[] array = new UByte[values.length];
        for (int i = 0; i < values.length; i++) {
            array[i] = ubyte(values[i]);
        }
        return array;
    }
482236
private static byte[] intToByteArray(int value)
    {
        byte[] data = new byte[4];

        // int -> byte[]
        for (int i = 0; i < 4; ++i)
        {
            int shift = i << 3; // i * 8
            data[3 - i] = (byte) ((value & (0xff << shift)) >>> shift);
        }
        return data;
    }
82375
public byte[] readVarArray() throws IOException {
    int len = (int) readVarLong();
    byte[] result = new byte[len];
    in.read(result);
    return result;
  }
93319
public static int writeDouble(byte[] array, int offset, double v) {
    return writeLong(array, offset, Double.doubleToLongBits(v));
  }
12666
public static Value int64Array(@Nullable long[] v) {
    return int64Array(v, 0, v == null ? 0 : v.length);
  }
1325276
public static int byteArrayToIntBE( byte[] data ) {
        if (data == null || data.length != 4)
            return 0x0;
        // ----------
        return (int) ( // NOTE: type cast not necessary for int
        (0xff & data[0]) << 24 | (0xff & data[1]) << 16 | (0xff & data[2]) << 8 | (0xff & data[3]) << 0);
    }
1340928
public static byte[] toUnsignedByteArray(int length, BigInteger value) {
		byte[] bytes = value.toByteArray();
		if (bytes.length == length) {
			return bytes;
		}

		int start = bytes[0] == 0 ? 1 : 0;
		int count = bytes.length - start;

		if (count > length) {
			throw new IllegalArgumentException("standard length exceeded for value");
		}

		byte[] tmp = new byte[length];
		System.arraycopy(bytes, start, tmp, tmp.length - count, count);
		return tmp;
	}
1269421
public static byte[] toBytes(Object value) {
        try {
            return mapper.writeValueAsBytes(value);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            throw new IllegalArgumentException(
              String.format("Could not transform to bytes: %s", e.getMessage()));
        }
    }
289536
public static String toStringLow(long[] v) {
    if(v == null) {
      return "null";
    }
    final int mag = magnitude(v);
    if(mag == 0) {
      return "0";
    }
    char[] digits = new char[mag];
    int pos = 0;

    outer: for(int w = 0; w < v.length; w++) {
      long f = 1L;
      for(int i = 0; i < Long.SIZE; i++) {
        digits[pos] = ((v[w] & f) == 0) ? '0' : '1';
        f <<= 1;
        ++pos;
        if(pos >= mag) {
          break outer;
        }
      }
    }
    for(; pos < mag; ++pos) {
      digits[pos] = '0';
    }
    return new String(digits);
  }
1119660
static public byte[] asByteArray(int value) {

        // check for 0
        if (0 == value) {
            return ZERO_BYTEARRAY;
        }

        // 2^31 is a 10 digit number so make space for the max size
        byte[] bytes = new byte[SIZE_MAXINT];
        // check for negative ints
        boolean bNegative = false;
        if (0 > value) {
            // force it positive for parsing
            bNegative = true;
            value = -value;
        }
        // now loop back through each digit in the int
        int index = SIZE_MAXINT - 1;
        for (; 0 <= index && 0 != value; index--) {
            bytes[index] = HEX_BYTES[value % 10];
            value /= 10;
        }

        // length is how ever many digits there were + a possible negative sign
        int len = (SIZE_MAXINT - 1 - index);
        if (bNegative) {
            len++;
        }

        // now copy out the "real bytes" for returning
        byte[] realBytes = new byte[len];
        for (int i = len - 1, x = SIZE_MAXINT - 1; 0 <= i; i--, x--) {
            realBytes[i] = bytes[x];
        }
        // add negative sign if we need to
        if (bNegative) {
            realBytes[0] = '-';
        }
        return realBytes;
    }
1155441
public static int byteArrayToIntLE( byte[] data ) {
        ByteBuffer buffer = ByteBuffer.wrap(data);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        return buffer.getInt();
    }
893731
public static byte[] toByteArray(Object obj) {
    int len = (int) sizeOf(obj);
    byte[] bytes = new byte[len];
    unsafe.copyMemory(obj, 0, bytes, Unsafe.ARRAY_BYTE_BASE_OFFSET, bytes.length);
    return bytes;
  }