Question

122 - /* 123 This function should only use bitwise operators and 124 relational operators 125 */ 126 // Add operation using o

In C how to add only using bitwise operations

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int _add(int a, int b) {
//Find carry
int carry = (a & b) << 1;
//Find sum of bits
int sum = a^b;
while(carry!=0){
//Update a and b
a = carry;
b = sum;
//Find carry and sum
carry = (a & b) << 1;
sum = a^b;
}
//Return sum
return sum;
}

int main()
{
printf("45 + 33 = %d\n",_add(33,45));

return 0;
}
OUTPUT :

20 hanno input 45 + 33 = 78 ... Program finished with exit code o Press ENTER to exit console.

Add a comment
Know the answer?
Add Answer to:
In C how to add only using bitwise operations 122 - /* 123 This function should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Use Excel) italy common for people to put on weight when they quit smoking While a...

    (Use Excel) italy common for people to put on weight when they quit smoking While a small weight gain is normal c e weight gain can create new health concerns that brode the benefits of not smoking. The accompanying table shows a portion of the weight data for 50 women before quitting and six months after quitting Use Table 2 Weight Before Quilling 140 144 138 Weight After Quilling 155 142 163 146 129 149 136 127 158 145 118...

  • Please do NOT use Minitab - show all calculations for creating the probability plot. Using Excel...

    Please do NOT use Minitab - show all calculations for creating the probability plot. Using Excel is okay. Reconsider Problem 3 in Homework 3. Is the set of measurements well described by a normal distribution? Show all the calculations. The measurements of a temperature sensor (in °F) are shown below. 124 118 131 125 133 123 120 119 128 133 127 125 131 124 129 121 142 151 160 125 121 136 140 137 125 124 128 129 130 141...

  • 4.15 construct a box plot for the data in exercise 4.1 down, then across Table 4B...

    4.15 construct a box plot for the data in exercise 4.1 down, then across Table 4B Electronic Component Failure Time 127 125 131 124 123 120 121 136 140 118 131 125 56 Chapter 4 Statistical Inference about Product Table 4E. Continued 119 128 133 137 124 142 123 137 125 124 128 129 130 122 133 124 129 121 142 151 160 125 141 125 140 131 129 126

  • Q1. A stimulus is being examined to determine its effect on systolic blood pressure. 18 men...

    Q1. A stimulus is being examined to determine its effect on systolic blood pressure. 18 men participate in the study. Each man’s systolic blood pressure is measured both before and after the stimulus is applied. The following statements input the data: SBPbefore 120 124 130 118 140 128 140 135 126 130 126 127 129 133 136 128 120 125 SBPafter 128 131 131 127 132 125 141 137 118 132 129 135 133 134 133 134 130 140 Is...

  • a. Calculate the sample average. b. Calculate the sample standard deviation. 4. The time to failure...

    a. Calculate the sample average. b. Calculate the sample standard deviation. 4. The time to failure in hours of an electronic component subjected to an accelerated life test is shown in Table 3E.1. To accelerate the failure test, the units were tested at an elevated temperature (read down, then across). a. Calculate the sample average and standard deviation. b. Construct a histogram. c. Construct a stem-and-leaf plot. d. Find the sample median and the lower and upper quartiles. TABLE 3E.1...

  • The measurements of a temperature sensor (in °F) are provided. Is the set of measurements well...

    The measurements of a temperature sensor (in °F) are provided. Is the set of measurements well described by a normal distribution? Calculate the R^2 and R^2 adjusted values. Show all the calculations. Order Temperature (F) 1 118 2 119 3 120 4 121 5 121 6 122 7 123 8 123 9 124 10 124 11 124 12 124 13 125 14 125 15 125 16 125 17 125 18 126 19 127 20 128 21 128 22 129 23...

  • In the following problems, assume that the population distributions are normal and have equal variances. Twenty-five...

    In the following problems, assume that the population distributions are normal and have equal variances. Twenty-five males between the ages of 25 and 30 who were participating in a well-known heart study carried out in Framingham, Massachusetts were randomly selected. Of these, 11 were smokers and 14 were not. The following data refer to readings of their systolic blood pressure: Smokers: 124, 134, 136, 125, 133, 127, 135, 131, 133, 125, 118 Non-Smokers: 130, 122, 128, 129, 118, 122, 116,...

  • How do I plot a series graph with this data provided? Month 1987 1988 1989 1990...

    How do I plot a series graph with this data provided? Month 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 Jan 95 104 101 88 132 125 111 127 119 147 Feb 94 100 96 110 109 118 123 129 147 146 Mar 98 99 82 129 101 121 121 132 164 133 Apr 96 88 84 113 111 140 139 108 135 148 May 95 89 85 114 140 141 119 115 124 141 Jun 115 108...

  • Maintaining a healthy weight is important for women’s health. Some physicians recommend being back to your...

    Maintaining a healthy weight is important for women’s health. Some physicians recommend being back to your pre-pregnancy weight six months after giving birth. Public health officials are interested in whether this is a realistic goal. Do the women in North Carolina weigh more than their pre-pregnancy weight six months postpartum? In other words, is the six months post-pregnancy weight greater than their pre-pregnancy weight? Use a paired samples t-test to compare pst6wght (variable 1) and prewght (variable 2). This uses...

  • why the error comes 100% E52 Wed 7:41 AM MATLAB R2016a g (CHUNG HA)-"Snap... EDITOR PUBLISH...

    why the error comes 100% E52 Wed 7:41 AM MATLAB R2016a g (CHUNG HA)-"Snap... EDITOR PUBLISH VIEW Close on S+one www.youtube.com insert Efx P Recommended: Stone Musl... Settings ment Breakpoints Run Run and Advance Run and ndent Advance Time LDIT BREAKPOINTS RUN ents MATLAB Editor /Users/xinyuli/Documents/MATLAB/EMEC 5671Assign2.m EMEC 5671Assign2.m bisect.m W4 + 117 118 W5.Duffing's oscillator function dxedxdt (t,x) 119 120 121 dx(1,1)x(2,1); dx(2,1)-e.25x (2,1)+x(1,1)-x(1,1)^3+0.3*cos (t) ; 122. 123- 124 125 end tspan [e 60]; xe [e;11 It,x]-ode45(@dxdt, tspan, x0)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT