set Bit for long value - Java Language Basics

Java examples for Language Basics:Bit

Description

set Bit for long value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        long bitmap = 2;
        int pos = 2;
        System.out.println(setBit(bitmap, pos));
    }/*from ww w. j  a va  2 s.  c o  m*/

    public static long setBit(long bitmap, int pos) {
        return bitmap | (1 << pos);
    }
}

Related Tutorials