Ask Question
8 September, 10:10

Given the following sequence of Java code: int var1 = 0b0001; int var2 = 0b1111; int results1 = var1 & var2; int results2 = var1 | var2; int results3 = var1 ^ var2; int printit = results1 + results2 + results3; What are the values for results1, results2, results3 and printit after executing the code?

+2
Answers (1)
  1. 8 September, 11:10
    0
    results1 = 1

    results2 = 15

    results3 = 14

    printit = 30

    Explanation:

    public class HelloWorld{

    public static void main (String []args)

    int var1 = 0b0001;

    int var2 = 0b1111;

    int results1 = var1 & var2;

    int results2 = var1

    }

    Output:

    $javac HelloWorld. java

    $java - Xmx128M - Xms16M HelloWorld

    1 15 14 30

    In this program we are performing binary operations with logical gates and binary numbers, to understand the result see each binary operation:

    var1 & var2: refers to the AND gate, since 0001 & 1111 is 0001 our result as an integer is 1 var1 | var2: refers to the OR gate, since 0001 | 1111 is 1111 our result as an integer is 15 var1 ^ var2: refers to the XOR gate, since 0001 ^ 1111 is 1110 our result as an integer is 14 results1 + results2 + results3: refers to the sum of 3 integers, 1+15+14 equal 30
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given the following sequence of Java code: int var1 = 0b0001; int var2 = 0b1111; int results1 = var1 & var2; int results2 = var1 | var2; ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers