Android Byte Array Reverse reverseWord(byte[] b)

Here you can find the source of reverseWord(byte[] b)

Description

reverse Word

Declaration

public static void reverseWord(byte[] b) 

Method Source Code

//package com.java2s;

public class Main {

    public static void reverseWord(byte[] b) {
        int len = 0;
        for (int i = b.length - 1; i >= 0; i--) {
            if ((b[i] & 0xff) != '\0') {
                len = i + 1;/*from  w w  w  . j av  a2s  .c  o m*/
                break;
            }
        }
        if ((len & 1) == 1) {
            b[len - 1] = '\0';
            len--;
        }
        for (int i = 0; i < len / 2; i += 2) {
            byte tmp = b[i];
            b[i] = b[len - 2 - i];
            b[len - 2 - i] = tmp;
            tmp = b[i + 1];
            b[i + 1] = b[len - 1 - i];
            b[len - 1 - i] = tmp;
        }
    }
}

Related

  1. reverse(byte[] data)
  2. reverse(byte[] original)
  3. reverseWordLatin(byte[] b)
  4. reverse(byte[] byteArray)
  5. reverseBytes(byte[] bytes)
  6. getReverseBytesInt(byte[] bb, int index)