set Bit to byte value - Java File Path IO

Java examples for File Path IO:Byte Array

Description

set Bit to byte value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte b = 2;
        int pos = 2;
        System.out.println(setBit(b, pos));
    }/*www . jav  a 2 s.  c o  m*/

    /**
     *
     * @param b
     * @param pos
     * @return
     */
    public static byte setBit(byte b, int pos) {
        return (byte) (b | (1 << pos));
    }
}

Related Tutorials