Java Array From toArray(long l, byte[] b, int offset)

Here you can find the source of toArray(long l, byte[] b, int offset)

Description

Encodes the specified long in 4 consecutive bytes (big-endian) in the specified array, beginning at the specified offset.

License

Apache License

Parameter

Parameter Description
l the long to encode
b the array into which the long should be written
offset the offset into the array at which the writing should begin

Declaration

public static void toArray(long l, byte[] b, int offset) 

Method Source Code

//package com.java2s;
/*   // w ww.  jav a2  s.  c  o m

 Copyright 2004, Martian Software, Inc.

 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.
    
 */

public class Main {
    /**
     * Encodes the specified long in 4 consecutive bytes (big-endian)
     * in the specified array, beginning at the specified offset.
     * @param l the long to encode
     * @param b the array into which the long should be written
     * @param offset the offset into the array at which the writing
     * should begin
     */
    public static void toArray(long l, byte[] b, int offset) {
        b[offset + 3] = (byte) (l % 256);
        l >>>= 8;
        b[offset + 2] = (byte) (l % 256);
        l >>>= 8;
        b[offset + 1] = (byte) (l % 256);
        l >>>= 8;
        b[0] = (byte) (l % 256);
    }
}

Related

  1. toArray(int time)
  2. toArray(int value)
  3. toArray(int value, byte b[], int offset)
  4. toArray(int[] intArray)
  5. toArray(Iterable itr)
  6. toArray(long value, byte[] dest, int offset, int length)
  7. toArray(Object a)
  8. toArray(Object foo)
  9. toArray(Object o)