Android Little Endian Convert uint32LittleEndian(int value)

Here you can find the source of uint32LittleEndian(int value)

Description

uint Little Endian

Declaration

public static int uint32LittleEndian(int value) 

Method Source Code

//package com.java2s;

public class Main {
    public static int uint32LittleEndian(int value) {
        value = (int) ((long) value & 0xFFFFFFFF);
        return swapBytes(value);
    }/*  w w w.  ja va 2  s  . co  m*/

    public static short swapBytes(short value) {
        int b1 = value & 0xff;
        int b2 = (value >> 8) & 0xff;

        return (short) (b1 << 8 | b2 << 0);
    }

    public static int swapBytes(int value) {
        int b1 = (value >> 0) & 0xff;
        int b2 = (value >> 8) & 0xff;
        int b3 = (value >> 16) & 0xff;
        int b4 = (value >> 24) & 0xff;

        return b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0;
    }

    public static long swapBytes(long value) {
        long b1 = (value >> 0) & 0xff;
        long b2 = (value >> 8) & 0xff;
        long b3 = (value >> 16) & 0xff;
        long b4 = (value >> 24) & 0xff;
        long b5 = (value >> 32) & 0xff;
        long b6 = (value >> 40) & 0xff;
        long b7 = (value >> 48) & 0xff;
        long b8 = (value >> 56) & 0xff;

        return b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 | b5 << 24
                | b6 << 16 | b7 << 8 | b8 << 0;
    }
}

Related

  1. intAsLittleEnd(int val)
  2. longAsLittleEnd(byte[] a, int i, long v)
  3. longAsLittleEnd(long val)
  4. shortAsLittleEnd(byte[] a, int i, short v)
  5. shortAsLittleEnd(short val)