Question

In: Computer Science

1. What is value of X after following operation int X=0x 45; X = X<<3 ;...

1. What is value of X after following operation

int X=0x 45;

X = X<<3 ; X=

What is value of X after following operation

int x=0x 40;

X = X>>3 ; X=

What is value of X after following operation

int x=0X FF;

X = X & 0x0F; X=

What is value of X after following operation

int x=0x FF;

X = ~X ; X=

What is value of X after following operation

int X=0x FF;

X = X &~(1<<4) ; X=

Solutions

Expert Solution

Literals that start with 0x are hexadecimal integers .

4 in binary = 0100

5 in binary = 0101

means 0x45 = 0100 0101

so int x =0x45 means in binary x will contain 0100 0101(with some preceding zeros according to compiler beacuse interger can take 32 or 64 bit according to compiler)

1.

int x= 0x45;

x=x<<3;

/*

given x =0000 0000 0000 0000 0000 0000 0100 0101

<< is left shift operator means we have to shift 3 bits towads left with inserting three extra zeros to right

takin 32 bit for integer

after applying bitwise left shift operator , shifting each bit to left by 3 bits

x= 0000 0000 0000 0000 0000 0010 0010 1000 = 552(in decimal number system)

*/

x= 552 // final answe

2.

int x= 0x40;

x=x>>3;

/*

x =0x40 means in binary x will contain 0100 0000(with some preceding zeros according to compiler beacuse interger can take 32 or 64 bit according to compiler)

given x =0000 0000 0000 0000 0000 0000 0100 0000

>> is right shift operator means we have to shift 3 bits towads right with inserting three extra zeros to left

takin 32 bit for integer

after applying bitwise right shift operator , shifting each bit to right by 3 bits

x= 0000 0000 0000 0000 0000 0000 0000 1000   = 8(in decimal number system)

*/

x= 8 // final answer

3.

int x=0X FF;

X = X & 0x0F;

/*

x =0xFF means in binary x will contain 1111 1111(with some preceding zeros according to compiler beacuse interger can take 32 or 64 bit according to compiler)

given x =0000 0000 0000 0000 0000 0000 1111 1111

& is bitwise AND operator, means we have to do bitwise anding (only 1&1=1, otherwise 0 for all cases)

x = 0000 0000 0000 0000 0000 0000 1111 1111

0x0F= 0000 0000 0000 0000 0000 0000 0000 1111 ( execute bitwise and for each bit)

X =   0000 0000 0000 0000 0000 0000 0000 1111

x= 0000 0000 0000 0000 0000 0000 0000 1111   = 15(in decimal number system)

*/

x=15 // final answer

4.

int x=0x FF;

X = ~X ;

/*

x =0xFF means in binary x will contain 1111 1111(with some preceding zeros according to compiler beacuse interger can take 32 or 64 bit according to compiler)

given x =0000 0000 0000 0000 0000 0000 1111 1111

x= 255 (in decimal)

~ is bitwise NOT operator, means we have to do bitwise negation of x;

simply in short ~x means -(x+1)

so here x= 255(in decimal)

after applying ~operator

x= -256;

*/

x= -256 // final answer

5.

X=0x FF;

X = X &~(1<<4) ;

/*

x =0xFF means in binary x will contain 1111 1111(with some preceding zeros according to compiler beacuse interger can take 32 or 64 bit according to compiler)

given x =0000 0000 0000 0000 0000 0000 1111 1111

1<<4 is 0000 0000 0000 0000 0000 0000 0001 0000 =(16 in decimal)

~ is bitwise NOT operator, means we have to do bitwise negation of x;

simply in short ~x means -(x+1)

so here ~(1<<4)= ~(16)= -17

x=x&~(1<<4); // apply bitwise and now

x=239;

*/

x= 239 // final answer


Related Solutions

1. What will be the value of numbers[1] after the following code is executed? int[] numbers...
1. What will be the value of numbers[1] after the following code is executed? int[] numbers = {22, 33, 44}; for(int k = 0; k < 3; k++) { numbers[k] = numbers[k] + 5; } } 2. What will be the results of the following code? final int ARRAY_SIZE = 5; double[] x = new double[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } 3.What is the value of numbers [3] after the following line...
What is the value of n after this code runs? 1 Point int n = 0;...
What is the value of n after this code runs? 1 Point int n = 0; int j = 7; if ((j!=0) && (n < 25)) { n = 1; if (j > 4) { n = 2; } else { n = 3; } } else { n = 4; if (j%2 >= 2) { n = 5; } else { n = 6; } }
With 3-digit rounding after each operation find the value of: a. 0.4 + 0.4 + …...
With 3-digit rounding after each operation find the value of: a. 0.4 + 0.4 + … + 0.4 + 100 (where the 0.4 is repeated 100 times) b. 100+0.4 + 0.4 + … + 0.4 (where the 0.4 is repeated 100 times) c. Find the absolute and relative error in parts a and b.
1. What is the highest value of x that satisfies this equation x(x+4) = -3
  1. What is the highest value of x that satisfies this equation x(x+4) = -3 A. -1 B. 0 C. 1 D. -3 2. If x2 - 9x = -18, what are the possible values of x? A. -3 and -6 B. -3 and 6 C. 3 and -6 D. 3 and 6 3. What polynomial can be added to 2x2 - 2x+6 so that the sum is 3x2+ 7x? A. 5x2+ 5x+ 6 B. 4x2+ 5x+ 6 C....
Answer the following What is the difference between these two methods? Void display(int x) Int display(int...
Answer the following What is the difference between these two methods? Void display(int x) Int display(int s) Write a one line of code to generate random numbers from 35 to 55.( not a full program) Draw the UML diagram for a switch statement with 4 cases . Write a while loop to output the value of the variable x starting from 5, decreasing it by 0.5 each time, as long as x remains positive. Write a for loop to display...
What is the net present value of Project X if it has the following after tax...
What is the net present value of Project X if it has the following after tax cash flows? The interest rate is 6%              End of year 1 = ($300)        End of year 2 = $500 End of year 3 = $900 Please show equation that is easy to understand, able to put into TI-84.
public class P2 { public static int F(int x[], int c) { if (c < 3)...
public class P2 { public static int F(int x[], int c) { if (c < 3) return 0; return x[c - 1] + F(x, c - 1); } public static int G(int a, int b) { b = b - a; a = b + a; return a; } public static void main(String args[]) { int a = 4, b = 1; int x[] = { 3, 1, 4, 1, 5 }; String s = "Problem Number 2"; System.out.println(x[2 +...
1.) What is the future value after 3 years of the cashflow below if the interest...
1.) What is the future value after 3 years of the cashflow below if the interest rate is 4%? YR: 1 2 3 CF: 500 400 300 2.) What is the present value of the cash flows above if the discount rate is 12%? Please show work + formulas used. Studying for an exam.
Suppose you are given the following prices: Current stock price is $41. Call(X=40)=$4.5, Call(X=45)=$3, Put(X=$45)=$3, Put(X=$40)=$2,...
Suppose you are given the following prices: Current stock price is $41. Call(X=40)=$4.5, Call(X=45)=$3, Put(X=$45)=$3, Put(X=$40)=$2, T=1 year, risk-free interest rate=5%. All options are American type. Is there a profit opportunity based on these prices? If so, what would you do? If not, why not?
What is the output of the following C program? #include<stdio.h> int fac (int x); void main(...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main( ) {                         for (int i=1; i<=2; i++)                                     printf("%d", fac(i)); } int fac(int x) {                         x = (x>1) ? x + fac(x-1) : 100);                         return x; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT