VOOZH about

URL: https://www.geeksforgeeks.org/php/add-two-numbers-without-using-arithmetic-operators-in-php/

⇱ Add Two Numbers Without using Arithmetic Operators in PHP - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Add Two Numbers Without using Arithmetic Operators in PHP

Last Updated : 12 Dec, 2023

This article will show you how to add two numbers without using Arithmetic operators in PHP. There are two methods to add two numbers, these are:

Using Bitwise Operators

We will use Bitwise Operator to add two numbers. First, we check num2 is not equal to zero, then Calculate the carry using & operator, and then use XOR operator to get sum of numbers, At last, shift the carry to 1 left.


Output
Sum : 12

Using Recursion

In this section, we will use the above approach with Recursion to calculate the sum of two numbers.

Example:


Output
Sum : 12
Comment
Article Tags: