Moves all bytes one down, meaning the right most byte (length-1) is swapped to the beginning - Android java.lang

Android examples for java.lang:Array Element

Description

Moves all bytes one down, meaning the right most byte (length-1) is swapped to the beginning

Demo Code


//package com.java2s;

public class Main {
    /**// w w  w  . j  ava2s  . c om
     * Moves all bytes one down, meaning the right most byte (length-1) is swapped to the beginning
     */
    public static byte[] rotateRight(byte[] input) {
        byte[] cycled = new byte[input.length];
        System.arraycopy(input, 0, cycled, 1, input.length - 1);
        cycled[0] = input[input.length - 1];
        return cycled;
    }
}

Related Tutorials