Here you can find the source of swap32bitsToArray(int value, byte[] dest, int offset)
Parameter | Description |
---|---|
value | The value to swap. |
dest | the destination array |
offset | the offset in the array where to put the swapped value. Array length must be at least offset + 4 |
public static void swap32bitsToArray(int value, byte[] dest, int offset)
//package com.java2s; /*/*from www.j a v a2s . co m*/ * Copyright (C) 2007 The Android Open Source Project * * 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 { /** * Swaps an unsigned value around, and puts the result in an array that can be sent to a device. * @param value The value to swap. * @param dest the destination array * @param offset the offset in the array where to put the swapped value. * Array length must be at least offset + 4 */ public static void swap32bitsToArray(int value, byte[] dest, int offset) { dest[offset] = (byte) (value & 0x000000FF); dest[offset + 1] = (byte) ((value & 0x0000FF00) >> 8); dest[offset + 2] = (byte) ((value & 0x00FF0000) >> 16); dest[offset + 3] = (byte) ((value & 0xFF000000) >> 24); } }