package org.kodejava.example.lang;
public class ANDDemo {
public static void main(String[] args) {
int numberA = 16;
int numberB = 16;
// Operator "&" is used for doing bitwise AND operation
int result = numberA & numberB;
System.out.println(numberA + " & " + numberB + " = " + result);
// Print the result in binary format
System.out.println(Integer.toBinaryString(numberA) +
" & " + Integer.toBinaryString(numberB) +
" = " + Integer.toBinaryString(result));
}
}
The result of the code snippet:
16 & 16 = 16
10000 & 10000 = 10000
Wayan Saryada
Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. If these posts help, you can support me, buy me a cup of coffee or tea. Thank you 🥳
Latest posts by Wayan Saryada (see all)
- How do I set the time of java.util.Date instance to 00:00:00? - October 24, 2019
- How to Install Consolas Font in Mac OS X? - March 29, 2019
- How do I clear the current command line in terminal? - February 14, 2019