Java Milliseconds getMillisFromByteArray(byte[] buff, int offset)

Here you can find the source of getMillisFromByteArray(byte[] buff, int offset)

Description

Extracts an milliseconds from seconds strored in a byte array.

License

Open Source License

Parameter

Parameter Description
buff the array to extract the millis from.
offset the offset to start reading from.

Exception

Parameter Description
IndexOutOfBoundsException if offset is negative or<code>buff.length</code> &lt; <code>offset + 4</code>.

Return

The value extracted.

Declaration

public static long getMillisFromByteArray(byte[] buff, int offset) 

Method Source Code

//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> &lt; <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;
    }
}

Related

  1. getMilliSeconds(String input)
  2. getMilliseconds(String time)
  3. getMilliseconds(String unixtime)
  4. getMillisecondsFromTimeString(String timeString)
  5. getMilliSecs()
  6. getMillisPartFromNanos(long nanos)
  7. getMillisSinceInit()
  8. getNumSamplesForMillisAtSampleRate(final int sampleRate, final float millis)
  9. getOLEDateFromMillisRounded(long millis)