JAVA programs

program using bitwise operator

In this program we see bitwise operator (which is bitwise operator?, how to use?, etc.)

Program

class Bitwiseoperatordemo

{

    public static void main(String[] args)

    {

        int x=11;

        int y=12;

        int z;

        z=x&y;

        System.out.println("The Bitwise AND operator:"+z);

        z=x|y;

        System.out.println("The Bitwise inclusive OR operator:"+z);

        z=~x;

        System.out.println("The Value of once compliment:"+z);

        z=x^y;

        System.out.println("The value of Bitwise exclusive OR:"+z);

        z=x<<y;

        System.out.println("The Bitwise LEFT shift operator:"+z);

        z=x>>y;

        System.out.println("The Bitwise RIGHT shift operator:"+z);

        z=x>>>y;

        System.out.println("The Bitwise RIGHT shift operator With zero fill:"+z);

        }

}

When Run The Program Following Output:

The Bitwise AND operator:8

The Bitwise inclusive OR operator:15

The Value of once compliment:-12

The value of Bitwise exclusive OR:7

The Bitwise LEFT shift operator:45056

The Bitwise RIGHT shift operator:0

The Bitwise RIGHT shift operator With zero fill:0

Description

 

Bitwise operator works on bits and performs bit-by-bit operation.

Following table shows bitwise operators.

 

Operator

Description

& (bitwise And)

The bitwise And Operator copies a bit to the result if it exists in both operands.

| (bitwise Or)

The bitwise OR Operator copies a bit if it exists in either operand.

^ (bitwise XOR)

The bitwise XOR Operator copies the bit if it is set in one operand but not both.

~ (bitwise compliment)

The bitwise Ones Complement Operator is unary and has the effect of 'flipping' bits or complements the bit.

<< (left shift)

The bitwise Left Shift Operator.

>> (right shift)

The bitwise Right Shift Operator.

 

Releted Programs

© 2017 codewmAll rights reserved.