Here you can find the source of getMillisFromByteArray(byte[] buff, int offset)
Parameter | Description |
---|---|
buff | the array to extract the millis from. |
offset | the offset to start reading from. |
Parameter | Description |
---|---|
IndexOutOfBoundsException | if offset is negative or<code>buff.length</code> < <code>offset + 4</code>. |
public static long getMillisFromByteArray(byte[] buff, int offset)
//package com.java2s; /*// w ww. j a v a 2s .c o m * $Id$ * * Copyright (c) 2008-2014 David Muller <roxon@users.sourceforge.net>. * All rights reserved. Use of the code is allowed under the * Artistic License 2.0 terms, as specified in the LICENSE file * distributed with this code, or available from * http://www.opensource.org/licenses/artistic-license-2.0.php */ public class Main { /** * Extracts an milliseconds from seconds strored in a byte array. The value * is four bytes in little-endian order starting at <code>offset</code>. * * @param buff the array to extract the millis from. * @param offset the offset to start reading from. * * @return The value extracted. * * @throws IndexOutOfBoundsException if offset is negative or * <code>buff.length</code> < <code>offset + 4</code>. */ public static long getMillisFromByteArray(byte[] buff, int offset) { long result; result = (buff[offset + 0] & 0x000000ff) | ((buff[offset + 1] & 0x000000ff) << 8) | ((buff[offset + 2] & 0x000000ff) << 16) | ((buff[offset + 3] & 0x000000ff) << 24); result *= 1000L; // convert from seconds to millis return result; } }