Question

In: Computer Science

Using C (not C++): setFirst - returns value with n upper bits set to 1 and...

Using C (not C++):

setFirst - returns value with n upper bits set to 1 and 32-n lower bits set to 0

* You may assume 0 <= n <= 32

* Example: setFirst(4) = 0xF0000000

* Legal ops: ! ~ & ^ | + << >> (NO IF OR FOR LOOPS)

* Max ops: 10

* Rating: 2

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

#include <stdio.h>

unsigned int setFirst(int n)
{
// take the number as 0.
unsigned int num=0;
  
// left shift the number of bits n and subtract 1 from the result.
num = (1 << (n)) - 1;
  
// shift the bits to right and return the answer
return num<<(32-n);
}
int main()
{
printf("n=4. It's Hex representation is %x\n",setFirst(4));
printf("n=8. It's Hex representation is %x\n",setFirst(8));
printf("n=15. It's Hex representation is %x\n",setFirst(15));

return 0;
}

==========


Related Solutions

Q8. If the bits 0 and 2 of P1IN are set, then toggle all the bits...
Q8. If the bits 0 and 2 of P1IN are set, then toggle all the bits of P1OUT simultaneously except the bit 4, else toggle only the bit 4 of P1OUT.
C++ Write a recursive function that computes and returns the product of the first n >=1...
C++ Write a recursive function that computes and returns the product of the first n >=1 real numbers in an array.
Have to use C language Pseudocode A #define called BITS should be set at the top...
Have to use C language Pseudocode A #define called BITS should be set at the top of the program. It should be set to 8 when the program is submitted. This define should be used throughout the entire program when setting/using array sizes/max element. This define will also be used in the output to print 8-bit vs 16 bit. Your program should function whether the define is set to 8 or to 16. Part of the grading process will be...
Determine the upper-tail critical value t(a/2) in each of the following a. 1-a = 0.95, n=50...
Determine the upper-tail critical value t(a/2) in each of the following a. 1-a = 0.95, n=50 b. 1-a = 0.99, n=50 c. 1-a = 0.95, n=63 d. 1-a = 0.95, n=35 e. 1-a = 0.90, n=56
Assume that bits is a string that only contains the characters "0" and "1". n is...
Assume that bits is a string that only contains the characters "0" and "1". n is an integer variable that is less than the length of bits. Fill in the blanks below to replace bits with a new string that consists of all of the characters of bits from index n through the end, followed by the first n characters of bits. For example, if bits was "1101010" and n was 3, the new value of bits would be "1010110"....
(1) Show that the set { 1 m + 1 n : m, n ∈ N}...
(1) Show that the set { 1 m + 1 n : m, n ∈ N} is countable. (2) Show that the set {a + b √ 2 : a, b ∈ Q} is countable. (3) Show that the intersection of two countable sets is countable. (4) Show that the set of all irrational numbers is uncountable. (5) Let C = {0, 1, 2, . . . , 9}. Show that the set C ×C × · · · is...
in the MSP430FR6989 what bits are set to “turn on” LCD_B1?  
in the MSP430FR6989 what bits are set to “turn on” LCD_B1?  
Test the hypothesis using the​ P-value approach. Upper H 0 : p equals 0.50 versus Upper...
Test the hypothesis using the​ P-value approach. Upper H 0 : p equals 0.50 versus Upper H 1 : p less than 0.50 n equals 150 comma x equals 66 comma alpha equals 0.10 Perform the test using the​ P-value approach. ​P-valueequals nothing ​(Round to four decimal places as​ needed.)
The bits transmitted by four stations A, B, C and D are multiplexed using Code Division...
The bits transmitted by four stations A, B, C and D are multiplexed using Code Division Multiplexing (CDMA). Assume A transmits a 1 bit, B transmits a 0 bit, C transmits a 1 bit, and D is silent. Assume the following are the chip sequences of the four stations, answer below questions: SA = (-1 -1 -1 +1 +1 -1 +1 +1); SC = (-1 -1 +1 -1 +1 +1 +1 -1) SB = (-1 +1 -1 +1 +1 +1...
[02] For n ≥ 1, how many strings of length n using letters a,b,c are there...
[02] For n ≥ 1, how many strings of length n using letters a,b,c are there if the letter a must occur an even number of times?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT