Android Byte Array to Int Convert swap32bitsToArray(int value, byte[] dest, int offset)

Here you can find the source of swap32bitsToArray(int value, byte[] dest, int offset)

Description

Swaps an unsigned value around, and puts the result in an array that can be sent to a device.

License

Apache License

Parameter

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

Declaration

public static void swap32bitsToArray(int value, byte[] dest, int offset) 

Method Source Code

//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);
    }
}

Related

  1. BytesToInt(byte[] value)
  2. bytesToInt(byte[] bytes)
  3. bytesToInt(byte[] bytes)
  4. bytesToInt(byte[] bytes, int offset)
  5. swap32bitFromArray(byte[] value, int offset)
  6. swapU16bitFromArray(byte[] value, int offset)
  7. toInt(byte[] in)
  8. parseInt(byte[] b, int start, int end, int radix)
  9. parseInt(byte[] b, int start, int end)