Java Bit Set setBit(byte in, int position, boolean value)

Here you can find the source of setBit(byte in, int position, boolean value)

Description

set Bit

License

Open Source License

Declaration

public static byte setBit(byte in, int position, boolean value) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte setBit(byte in, int position, boolean value) {
        if (!value) {
            return (byte) (in & (0xFF ^ 1 << 8 - position));
        } else {/*www.jav  a 2s  . c o m*/
            return setBit(in, position);
        }
    }

    public static short setBit(short in, int position, boolean value) {
        if (!value) {
            return (short) (in & (0xFFFF ^ 1 << 16 - position));
        } else {
            return setBit(in, position);
        }
    }

    public static byte setBit(byte in, int position) {
        in |= 1 << 8 - position;
        return in;
    }

    public static short setBit(short in, int position) {
        in |= 1 << 16 - position;
        return in;
    }
}

Related

  1. setBit(byte b, int pos)
  2. setBit(byte data, byte bit, boolean value)
  3. setBit(byte data, int bitNumber, boolean value)
  4. setBit(byte data, int bitPos, boolean on)
  5. setBit(byte data, int pos, int val)
  6. setBit(byte input, int bit)
  7. setBit(byte original, int bitToSet)
  8. setBit(byte target, byte pos)
  9. setBit(byte v, int position, boolean value)