Add Two Numbers Without using Arithmetic Operators in PHP Last Updated : 12 Dec, 2023 Comments Improve Suggest changes Like Article Like Report 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: Table of Content Using Bitwise OperatorsUsing RecursionUsing Bitwise OperatorsWe 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. PHP <?php function addNum($num1, $num2) { while ($num2 != 0) { // Calculate the carry $carry = $num1 & $num2; // XOR to get the sum $num1 = $num1 ^ $num2; // Shift the carry to the left $num2 = $carry << 1; } return $num1; } // Driver Code $num1 = 5; $num2 = 7; echo "Sum : " . addNum($num1, $num2); ?> OutputSum : 12 Using RecursionIn this section, we will use the above approach with Recursion to calculate the sum of two numbers. Example: PHP <?php function addNum($num1, $num2) { if ($num2 == 0) { return $num1; } else { return addNum($num1 ^ $num2, ($num1 & $num2) << 1); } } // Driver Code $num1 = 5; $num2 = 7; echo "Sum : " . addNum($num1, $num2); ?> OutputSum : 12 Comment More infoAdvertise with us Next Article Add Two Numbers Without using Arithmetic Operators in PHP B blalverma92 Follow Improve Article Tags : PHP PHP-math Geeks Premier League 2023 Similar Reads How to convert a String into Number in PHP ? Strings in PHP can be converted to numbers (float/ int/ double) very easily. In most use cases, it won't be required since PHP does implicit type conversion. This article covers all the different approaches for converting a string into a number in PHP, along with their basic illustrations.There are 4 min read How to extract Numbers From a String in PHP ? Extracting numbers from a string involves identifying and isolating numerical values embedded within a text. This process can be done using programming techniques, such as regular expressions, to filter out and retrieve only the digits from the string, ignoring all other characters.Here we have some 3 min read How to convert an Integer Into a String in PHP ? The PHP strval() function is used to convert an Integer Into a String in PHP. There are many other methods to convert an integer into a string. In this article, we will learn many methods.Table of ContentUsing strval() function.Using Inline variable parsing.Using Explicit Casting.Using sprintf() Fun 3 min read PHP program to print an arithmetic progression series using inbuilt functions We have to print an arithmetic progressive series in PHP, between two given numbers a and b both including, a given common arithmetic difference of d. Examples: Input : $a = 200, $b = 250, $d = 10 Output : 200, 210, 220, 230, 240, 250 Input : $a = 10, $b = 100, $d = 20 Output : 10, 30, 50, 70, 90Th 2 min read How to find Sum the Digits of a given Number in PHP ? We will explore how to find the sum of the digits of a given number in PHP. This task involves extracting each digit from the number and adding them together to get the final sum. Table of Content Using a loop to extract digits one by oneUsing mathematical operations to extract digitsUsing a loop to 2 min read How to Convert Number to Character Array in PHP ? Given a number, the task is to convert numbers to character arrays in PHP. It is a common operation when you need to manipulate or access individual digits of a number. This can be particularly useful in situations where you need to perform operations on the digits of a number, such as digital root 3 min read How to Convert a Given Number to Words in PHP? Given an integer N, your task is to convert the given number into words using PHP.Examples:Input: N = 958237764Output: Nine Hundred Fifty Eight Million Two Hundred Thirty Seven Thousand Seven Hundred Sixty FourInput: N = 5000Output: Five ThousandBelow are the approaches to convert a given number to 5 min read Program to print multiplication table of any number in PHP In this article, we will see how to print the multiplication table of any given number using PHP. To make the multiplication table, first, we get a number input from the user and then use for loop to display the multiplication table. We use HTML and PHP to display the multiplication table. The HTML 1 min read PHP Program to Print ASCII Value of all Digits of a Given Number Given a number, the task is to print ASCII value of all digits of a given number in PHP. ASCII values are often used to represent characters and digits. Sometimes, it's necessary to find the ASCII value of each digit in a given number, especially when dealing with character encoding or data manipula 3 min read Write a program to display Reverse of any number in PHP ? Write a program to reverse the digits of an integer. Examples : Input : num = 12345 Output: 54321 Input : num = 876 Output: 678 It can be achieved using Iterative way or Recursive Way Iterative Method: Algorithm: Input: num (1) Initialize rev_num = 0 (2) Loop while num > 0 (a) Multiply rev_num by 2 min read Like