Given the following code fragment:
int * SW_Ptr;
*SW_Ptr = 0x00000987;
int Nib2 = (*SW_Ptr >> 8) & 0xF;
int Nib1 = (*SW_Ptr >> 4) & 0xF;
int Nib0 = (*SW_Ptr) & 0xF;
Which is the correct value of Nib1, Nib2, Nib3.
Microcontrollers using c prog
Solution:
Given *SW_Ptr = 0
00000987
(Value is in hexadecimal format)
(a)
Finding the value of Nib2 :
=> As in the code given Nib2 = (*SW_Ptr >>8) &
0
F;
Converting the hexadecimal values to binary :
=> *SW_Ptr = 0
00000987
= 0000 0000 0000 0000 0000 1001 1000 0111
=> 0
F
= 1111
We can see >> is a right shift operator so performing right shift with *SW_Ptr by 8 bits.
=> 0000 0000 0000 0000 0000 1001 1000 0111 >> 8 => 0000 0000 0000 0000 0000 0000 0000 1001
Now we can see & is bitwise AND operator so performing bitwise AND
=> 0000 0000 0000 0000 0000 0000 0000 1001 & 1111 => 0000 0000 0000 0000 0000 0000 0000 1001
So finally the result is 0000 0000 0000 0000 0000 0000 0000 1001 in binary so converting the result into hexadecimal.
=> 0000 0000 0000 0000 0000 0000 0000 1001 = 0
00000009
So the value of Nib2 = 0
00000009
(b)
Finding the value of Nib1:
=> As in the code given Nib1 = (*SW_Ptr >>4) &
0
F;
Converting the hexadecimal values to binary :
=> *SW_Ptr = 0
00000987
= 0000 0000 0000 0000 0000 1001 1000 0111
=> 0
F
= 1111
We can see >> is a right shift operator so performing right shift with *SW_Ptr by 4 bits
=> 0000 0000 0000 0000 0000 1001 1000 0111 >> 4 => 0000 0000 0000 0000 0000 0000 1001 1000
Now we can see & is bitwise AND operator so performing bitwise AND
=> 0000 0000 0000 0000 0000 0000 1001 1000 & 1111 = 0000 0000 0000 0000 0000 0000 0000 1000
So finally the result is 0000 0000 0000 0000 0000 0000 0000 1000 in binary so converting the result into hexadecimal.
=> 0000 0000 0000 0000 0000 0000 0000 1000 = 0
00000008
So the value of Nib1 = 0
00000008
(c)
Finding the value of Nib3:
=> Given in the code its Nib0 and I think it's written by mistake so I am assuming it Nib3
Nib3 = (*SW_Ptr ) & 0
F;
Converting the hexadecimal values to binary :
=> *SW_Ptr = 0
00000987
= 0000 0000 0000 0000 0000 1001 1000 0111
=> 0
F
= 1111
We can see & is bitwise AND operator so performing bitwise AND
=> 0000 0000 0000 0000 0000 1001 1000 0111 & 1111 = 0000 0000 0000 0000 0000 0000 0000 0111
So finally the result is 0000 0000 0000 0000 0000 0000 0000 0111 in binary so converting the result into hexadecimal.
=> 0000 0000 0000 0000 0000 0000 0000 0111 = 0
00000007
So the value of Nib3 = 0
00000007
I have explained each and every part of the question with the help of the operator understanding and performing the operations as well.
Given the following code fragment: int * SW_Ptr; *SW_Ptr = 0x00000987; int Nib2 = (*SW_Ptr >>...
( C prog) write an output for the following code fragment int a[]= {1, 2, 3, 4, 5, 6}: int *ip; int i; ip=a; ip +=3; *ip= *ip * 3; for (i=0; i <6; ++i) printf("%d," a[i]);
8. Given the following code fragment and function definition, what is(are) the output(s)? int funct (int n) int var = 1; while(n > 0) cout << funct(7)<<" "<<funct(0); var *= n; n--; return var;
Question 31 -Given the following code fragment, what value is contained in myArr[O]? const int ARRAYSIZE 3 double() myArr new double [ARRAYSIZE] myArr [0]1.1 myArr [1]2.2; myArr [2] myArr [0] myArr[1 O3.3 2.2 O 1.1 0 Question 32 - Given the following code fragment, what is displayed in IblResult? const int ARRAYSIZE 3 double(] myArr - new double [ARRAYSIZE] myArr [0] - 1.1 myArr [1] 2.2 lblResult.Text - Convert.Tostring (myArr (01) 3.3 O 2.2 1.1 0 Question 33 - Given...
Given the following Java code fragment, what is output? int a, b; String c, d, e; String x = new String(“I LOVE”); String y = “java!”; a = x.length( ); System.out.println(“1) “ + a); b = y.length( ); System.out.println(“2) “ + b); c = y.toUpperCase( ); System.out.println(“3) “ + c); d = x.toLowerCase( ); System.out.println(“4) “ + d); e = x.concat(y); System.out.println(“5) “ + e);
Please use induction
Consider the following code fragment: int i -1; int s=1; while (i <- n) Show that at the start of every iteration holds using induction
I don’t understand can you help
5. Given the definition and code fragment: (2 points int matrix[2]13]; int k = 0; for(int i =0; i < 2; i++) for (int j=0, j < 3 ) matrix[i]lj]-k++; The value of matrix[1][1] is
What is the output of the following code fragment? int i = 1; while( i <= 5 ) if(i == 2 || i == 4) System.out.println(i + ":" + " is an even index) System.out.println("i: " + i); i++;
What is the likely results of running the following code fragment? Why? int *ptr = (int *) 0xfeedbeef ; *ptr = 0 ; Suppose a class uses a dynamically-allocated integer array, pointed to by an int* variable named data. The current capacity of the array is stored in the integer variable capacity. The following code fragment is meant to dyamically resize the array, doubling its capacity. What is the major memory error and how would you detect it? int *tmp...
Consider the following pseudo-code fragment. What is the value of mystery(2, 3)? BEGIN PROGRAM mystery(int a, int b) IF (b==1) RETURN a END IF ELSE RETURN a + mystery(a, b - 1) END ELSE END PROGRAM mystery 2 4 6 8 the program generates a run time error (infinite recursion) I have no idea
What is the value of x[2] after execution of this code fragment? int x[4] = {3, 6, 9, 5}; x[2] -= x[1] % x[3]; 1 2 3 8