Here you can find the source of IntToByteArray(int val, byte[] buf, int offset)
Parameter | Description |
---|---|
val | Integer value |
buf | Byte array |
offset | Offset into the byte array |
public static void IntToByteArray(int val, byte[] buf, int offset)
//package com.java2s; /*/*from ww w.j av a2s .c o m*/ * * Copyright (c) 2015 University of Massachusetts * * 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. * * Initial developer(s): Westy * */ public class Main { /** * Write integer into buf[offset]...buf[offset+3] * * @param val Integer value * @param buf Byte array * @param offset Offset into the byte array */ public static void IntToByteArray(int val, byte[] buf, int offset) { buf[0 + offset] = (byte) ((val >> 24) & 255); buf[1 + offset] = (byte) ((val >> 16) & 255); buf[2 + offset] = (byte) ((val >> 8) & 255); buf[3 + offset] = (byte) (val & 255); } /** * Write integer into buf[0]...buf[3] * * @param val Integer value * @param buf Byte array */ public static void IntToByteArray(int val, byte[] buf) { IntToByteArray(val, buf, 0); } }