invert All But First Byte - Java java.lang

Java examples for java.lang:byte Array Bit Operation

Description

invert All But First Byte

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] bytes = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(java.util.Arrays
                .toString(invertAllButFirstByte(bytes)));
    }//from   w  w w. j ava  2 s .  c  o  m

    public static final int SKIP_FIRST = 1;

    public static byte[] invertAllButFirstByte(byte[] bytes) {

        for (int i = SKIP_FIRST; i < bytes.length; i++) {
            bytes[i] ^= 0xff;
        }
        return bytes;
    }
}

Related Tutorials