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....
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.
1)What is the output of the following code? struct someType { int a; int b; };...
1)What is the output of the following code? struct someType { int a; int b; }; void f1(someType &s) { s.a = 1; s.b = 2; } someType f2(someType s) { someType t; t = s; s.a = 3; return t; } int main() { someType s1, s2; f1(s1); s2 = f2(s1); cout << s1.a << '-' << s1.b << '-' << s2.a << '-' << s2.b << '-' << endl; return 0; } ------------------------------------------------------------------------------------------------------------------ 2) struct dateType { int...
What are the values of a, b, c, d, and e after the following statements? int...
What are the values of a, b, c, d, and e after the following statements? int a = 5, b = 2, c = 8, d = 7, e = 4; int x = c - b + a; a = a + x - d; b = c * d - x; c = e + a / 2; d = x - c * a; e = x + d - c;
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?
Consider the function f(x)=A(1+x/3) for –1 < x < 1. Find the value of A that...
Consider the function f(x)=A(1+x/3) for –1 < x < 1. Find the value of A that makes this function a pdf. Find the probability that X<1/2. Find the cdf of X. Use the cdf to find the probability that X > -1/2.
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;       char B=10; cout<<”Enter Value of A”; cin<<A; show(A) show(50)          }       cin.get(); } int show(int x); { cout<<”Value is =” <<X cout<<endl; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT