Question

What is the result of 2^7 in Java? Why does it give this result?

What is the result of 2^7 in Java? Why does it give this result?

Homework Answers

Answer #1

Answer: 5

^(bitwise XOR operator)

  • ^ is used as bitwise XOR operator in java
  • ^ returns 1 if both operand values are different and return 0 if both operand values are equal
A B A^B
0 0 0
1 0 1
0 1 1
1 1 0
  • 8 bit binary form of 2 is 00000010
  • 8 bit binary form of 7 is 00000111
  • Perform XOR operation bitwise on 00000010 and 00000111
  • 00000010 ^
  • 00000111
  • 00000101 which is the binary equivalent of 5 (1x22+0x21+1x20 = 4+0+1=5)
  • So 2^7 produce result 5
Know the answer?
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
Similar Questions
What is the result of 2^7 in Java? Why does it give this result? What would...
What is the result of 2^7 in Java? Why does it give this result? What would you use to get the result you would have expected before taking this class?
what is type erasure? why does Java use it when dealing with templated generic classes? what...
what is type erasure? why does Java use it when dealing with templated generic classes? what does java do instead
When does variable costing and absorption costing give similar result ? What makes the result of...
When does variable costing and absorption costing give similar result ? What makes the result of the two methods differ? Give a short explanation
Confidence Intervals Why does increasing the confidence level result in a larger margin of error? [2...
Confidence Intervals Why does increasing the confidence level result in a larger margin of error? [2 sentences]
java: can anyone explain. why does my code print out ##### and ***** instead of just...
java: can anyone explain. why does my code print out ##### and ***** instead of just #####? int a=1, b=2, c=3;    if(a<b) System.out.println("####"); else System.out.println("&&&&"); System.out.println("****");
What is the Java Virtual Machine? What purpose does it serve & how does it facilitate...
What is the Java Virtual Machine? What purpose does it serve & how does it facilitate program portability?
7. Explain the term Crowding In. What does it refer to, why would it be considered...
7. Explain the term Crowding In. What does it refer to, why would it be considered beneficial, and does this mean there is no crowding out? (7 points)
Define allosteric regulation. Does this type of regulation result in activation, inhibition, or both? Give an...
Define allosteric regulation. Does this type of regulation result in activation, inhibition, or both? Give an example of allosteric regulation.
Java: How does Recursion change my view on repetition, and why do I need to be...
Java: How does Recursion change my view on repetition, and why do I need to be concerned about Optimality? As usual, Please comment on two of your classmates posts.
Why does a large radius of curvature give a large focal point and why does a...
Why does a large radius of curvature give a large focal point and why does a small radius give a small focal? Using Snell's law to explain. Why do light rays that strike the edge of the lens bend more than light rays that strike the center? Using Snell's Law and the behavior of Principal Rays to explain.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT