Java Array Invert invert(byte[] bytes)

Here you can find the source of invert(byte[] bytes)

Description

Invert the provided byte array.

License

Apache License

Parameter

Parameter Description
bytes a parameter

Return

a byte array with all 0s flipped to 1s and 1s flipped to zeroes

Declaration

public static byte[] invert(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from w ww  .  ja  v  a  2  s.co m
     * Invert the provided byte array.
     * 
     * @param bytes
     * @return a byte array with all 0s flipped to 1s and 1s flipped to zeroes
     */
    public static byte[] invert(byte[] bytes) {
        byte[] invertedBytes = new byte[bytes.length];
        for (int i = 0; i < bytes.length; i++) {
            invertedBytes[i] = (byte) (~bytes[i]);
        }
        return invertedBytes;
    }
}

Related

  1. invert(boolean[] binary)
  2. invert(boolean[] result)
  3. invert(byte abyte0[])
  4. invert(byte[] array)
  5. invert(byte[] key)
  6. invert(byte[] v)
  7. invert(double[] ary)
  8. invert(float[] a)