0% found this document useful (0 votes)
14 views2 pages

Bitwise Operators in Java

Uploaded by

syediliyas8282
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Bitwise Operators in Java

Uploaded by

syediliyas8282
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name: Syed iliyas

Practical No:1(A)

Aim: program on bitwise opeator

public class BitwiseOperatorDemo {


public static void main(String[] args) {
int a = 5; // Binary: 0101
int b = 3; // Binary: 0011

// Bitwise AND
[Link]("a & b = " + (a & b)); // Output: 1 (0001)

// Bitwise OR
[Link]("a | b = " + (a | b)); // Output: 7 (0111)

// Bitwise XOR
[Link]("a ^ b = " + (a ^ b)); // Output: 6 (0110)

// Bitwise NOT
[Link]("~a = " + (~a)); // Output: -6 (inverts bits)

// Left Shift
[Link]("a << 1 = " + (a << 1)); // Output: 10 (1010)

// Right Shift
[Link]("a >> 1 = " + (a >> 1)); // Output: 2 (0010)
}
}

You might also like