This is the java program to perform addition of two numbers without using any arithmetic operators. The summation of two numbers can be obtained using XOR operation and carry can be obtained using AND performed at bit level.
Here is the source code of the Java Program to Perform Addition Operation Using Bit-wise Operators. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
//This is sample program to perform addition operation using bitwise operators.
public class Bitwise_Addition
static int add(int x, int y)
carry = x & y;
x = x ^ y;
y = carry << 1;
public static void main(String args)
Scanner input = new Scanner(System.in);
System.out.println("Enter the numbers to be added:");
int x = input.nextInt();
int y = input.nextInt();
System.out.println("The Summation is: "+add(x, y));
$ javac Bitwise_Addition.java
$ java Bitwise_Addition
Enter the numbers to be added:
The Summation is: 31
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
- Get Free Certificate of Merit in Java Programming
- Participate in Java Programming Certification Contest
- Become a Top Ranker in Java Programming
- Take Java Programming Tests
- Chapterwise Practice Tests: Chapter 1,
- Chapterwise Mock Tests: Chapter 1,
, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry
. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms.
Stay connected with him at LinkedIn
Subscribe to his free Masterclasses at Youtube
& technical discussions at Telegram SanfoundryClasses