Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 3 and 4 Evaluate each of these Java bit-operator expressions. Express yo

ID: 3889057 • Letter: P

Question

Problem 3 and 4 Evaluate each of these Java bit-operator expressions. Express your answers as a decimal numbers. (We know that you could just write a small Java program to get your Answers, but remember that you won't be able to use a computer on a quiz or an exam!) Assume integers. (a) 29 & 11 (b) 7| 17 Using a umask of 64 and a default permission value of 644, determine the initial file permission bits, expressed as a three-digit octal value, that would be assigned to a newly-created Linux file.

Explanation / Answer

Answer 3)
Given that the numbers are 6-bit integers. So the first step would be to write the numbers in binary.
To convert a number to binary repeatedly divide the number (quotient) by 2 and take the remainder. Now write down the remainders
from last step to 1st step to get the binary representation.

a) Convert 29 to binary

Below shown are steps to convert to binary, Q means Quotient and R means remainder
29 / 2 = [Q = 14, R = 1]
14 / 2 = [Q = 7, R = 0]
7 / 2 = [Q = 3, R = 1]
3 / 2 = [Q = 1, R = 1]
1 / 1 = [Q = 0, R = 1]

Now taking the remainders from last to first step, we get 29 in binary is 11101
Using 6 bits , 29 = 011101

Similarly lets convert 11.
11 / 2 = [Q = 5, R = 1]
5 / 2 = [Q = 2, R = 1]
2 / 2 = [Q = 1, R = 0]
1 / 2 = [Q = 0, R = 1]
Now taking the remainders from last to first step, we get 1011
Using 6bits, 11(decimal) = 001011

Now we know the 6 bit binary representation of the 2 numbers. We need to use & operator on the 2 numbers
The operation is applied on each corresponding bit and the output bit is a 0 when either of the bits is 0 and
output bit is a 1 iff both the bits are 1.
So , lets perform & operation
011101 = 29(decimal)
001011 = 11(decimal)
====================
001001 = 9 (decimal)


We got the result of operation 29 & 11 = 001001 in binary which when converted to decimal is 9. To convert a number from
binary to decimal, add the power of 2 for the corresponding bit (a bit which is 1) . The powers of 2 start with 2^0 from left most bit.
So counting from left, only the 0th and 3rd bits are 1 , so we add the corrsponding powers of 2 i.e 2^3 + 2^0 = 8 + 1 = 9.

So the answer for 29 & 11 = 9


==================================
b)Following the same steps as explained above, lets first convert 7 and 17 to 6 bit binary numbers
7 / 2 = [Q = 3, R = 1]
3 / 2 = [Q = 1, R = 1]
1 / 2 = [Q = 0, R = 1]
So 7 in binary = 111. Using 6 bits , 7 = 000111

Next lets convert 17
17 / 2 = [Q = 8, R = 1]
8 / 2 = [Q = 4, R = 0]
4 / 2 = [Q = 2, R = 0]
2 / 2 = [Q = 1, R = 0]
1/ 2 = [Q = 0, R = 1]
So 17 in binary = 10001. Using 6bits , 17 = 010001

Now lets perform | i.e OR operation. The output bit is a 1 when atleast one of the 2 bits is 1 and the output is 0 when both the bits are 0

000111 = 7
010001 = 17
============
010111 = 23

So the result of OR operation is 010111 in binary which when converted to decimal is 0+ 16+ 0 + 4 + 2 + 1 = 23

So the answer for 7 | 17 = 23

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote