What is the code and pseudocode for a 3 bit adder in an ardu

What is the code and pseudocode for a 3 bit adder in an arduino board. I am looking for either c++ or java programming.

Solution

// Java program to Compare 50 Random numbers vs BST with Random Numbers
//JAva Program to add Binary numbers
class Binaryadd
{
   public static void main(String[] args)       //main function ,execution starts from here
       {
           BinaryAddition(\"100\",\"001\");       //calling function with 3 bit arguments
       }
   public static void BinaryAddition(String s1,String s2)       //function defination for adding binary numbers any length not only 3 bit
{
int l1=s1.length();int c1=l1;       //length of binary number1                      
int l2=s2.length();int c2=l2;       //length of binary number2  
int max=(int)Math.max(l1,l2);       //finding max length bianry number
int arr1[]=new int[max];           //decalre aar1,arr2 with max length of bianry number
int arr2[]=new int[max];
int sum[]=new int[max+1];           //sum is stored in sum
for(int i=(arr1.length-1);i>=(max-l1);i--)           //loop to store binary string 1 to integer arr1
{
arr1[i]=(int)(s1.charAt(c1-1)-48);
c1--;
}
for(int i=(arr2.length-1);i>=(max-l2);i--)               //loop to store binary string 2 to integer arr2
{
arr2[i]=(int)(s2.charAt(c2-1)-48);
c2--;
}
for(int i=(sum.length-1);i>=1;i--)               //loop to sum binary num1 & num2
{
sum[i]+=arr1[i-1]+arr2[i-1];
if(sum[i]==2)                               //if two one bits addition set sum value as 0 and carry 1
{
sum[i]=0;
sum[i-1]=1;
}
else if(sum[i]==3)                           //if three one bits addition set sum value as and carry 1
{
sum[i]=1;
sum[i-1]=1;
}
}
int c=0;
for(int i=0;i<sum.length;i++)           //display output after binary addition
{
System.out.print(sum[i]);
}
}
  
}

Output :

for 100,001 inputs output is 0101

What is the code and pseudocode for a 3 bit adder in an arduino board. I am looking for either c++ or java programming.Solution// Java program to Compare 50 Ran

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site