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?
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
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?
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: 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.
JAVA - take each for loop and rewrite as a while statement a) int result =...
JAVA - take each for loop and rewrite as a while statement a) int result = 0; for (int i = 1; i <= 10; i++) { result = result + i;} System.out.println(result); b) int result = 1; for (int i = 1; i <= 10; i++) {result = i - result;} System.out.println(result); c) int result = 1; for (int i = 5; i > 0; i--) {result = result * i;} System.out.println(result); d) int result = 1; for (int...
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 Give an example of a class that contains at least one class variable and at...
java Give an example of a class that contains at least one class variable and at least one class method. Explain why using a class variable and method rather than an instance variable and method would be the correct choice in the example you select.