please explain how does the following C code work.
a)
int function1(int num1, int num2) {
int num = num1 ^ num2;
int result = 0;
while(num > 0) {
result += (num & 1);
num >>= 1;
}
return result;
}
b)
int function2(unsigned int num) {
return num & ~(num - 1);
}
c)
int f1(unsigned int x) {
int count = 0;
while(x) {
count++; x = x&(x-1);
}
return count;
}
d) double ldexp(double x, int exponent) is a C math function
that returns x multiplied
by 2 raised to the power of exponent. How many narrowing and how
many promotions
happen automatically in the following code line? Name them one by
one and explain each
one separately.
float f = 2.2f * ldexp(24.4, 3.0 * 2) - 4.4;
e)
int main() {
int a[] = {1, 2, 3, 4, 5};
int *b = a; int **c = &b;
printf("%d\n", **c*2);
printf("%d\n", **c-2*4);
printf("%d\n", **c+1-*b+1);
return 0;
}
Thanks!
In: Computer Science
Below is for C language
typedef struct _node {
Node *next;
char *str;
} Node;
You are given a function that takes in two Node* pointers to two different linked lists. Each linked list node has a string represented by a character array that is properly null terminated. You're function is supposed to return true if the concatenation of strings in a linked list match each other, else return false.
EXAMPLES
List 1: "h" -> "el" -> "l" -> "o" -> NULL
List 2: "he" -> "llo" -> NULL
Return: True
List 1: "je" -> "lc -> "l" -> "o" -> NULL
List 2: "h" -> "e" -> "ll" -> "" -> "o" -> NULL
Return: False
List 1: “e” -> “llo” -> “h” -> NULL
List 2: “h” -> “e” -> “l” -> “l” -> “o” -> NULL
Return: False
bool areListsMatching(Node *list1, Node *list2) {
// TODO: Fill this
}
In: Computer Science
Fill in the following table to show how the given integers are represented, assuming 16 bits are used to store values and the machine uses 2’s complement notation. (This is not necessarily MARIE.) Give values in the last two columns in hexadecimal as they would appear memory assuming the byte at address a is on the left and the byte at the address a+1 is on the right.
2-Byte Big |
2-Byte Little |
||||
Integer |
Binary |
Hex |
Endian (hex) |
Endian (hex) |
|
Example |
-540 |
1111 1101 1110 0100 |
FDE4 |
FD E4 |
E4 FD |
a) |
12 |
||||
b) |
-12 |
||||
c) |
128 |
||||
d) |
-128 |
||||
e) |
65,000 |
||||
f) |
-65,000 |
||||
byte a | byte a+1 |
byte a | byte a+1 |
In: Computer Science
You need to determine the kind of class a particular variable is. How can you determine this? How can you determine its identifier?
Explain the operations performed and their order in evaluating the following expression, and give the result of that evaluation. -- var = -8.0 + 3.0 * 4.5 – 2.0 / 33.0
Write a statement that assigns the integer portion of a floating point variable named wraps to wholewraps as a floating point variable.
Show by a Python code example how to load the Python math library and then determine the square root of the variable gross.
In: Computer Science
C++ programming question
theNumbers.txt
144 + 26
3 * 18
88 / 4
22 – 8
16 / 2
20 * 20
-Your Program should read in all items, compute the answer to each expression (any decimals should be rounded to the nearest tenth), and output the answers to an output file of the user's choosing. The formatting of the output is that there is a set width of 10 characters for each answer, left aligned, with a new line character every 3 answers. A sample “answers.txt” is provided below. (not drawn to scale)
answers.txt
17000 54 22
14 8 400
-You may assume that the name of the text file that will be outputted to is always 20 characters or less.
-You may assume that there are only 4 possible operations ( + - * /), add, subtract, multiply, and decimal division, and that no other characters will show up as the middle symbol.
- Appropriate error messages should be displayed if the file cannot be opened.
- Extra Credit: The answers in the output file ONLY show a decimal if the answer is not a whole number answer.
In: Computer Science
Using python, please complete these 4 exercises. Please limit your code to these skills:
For loop
While loop
Input function
F strings
Tuples
Lists
Nested ifs
Elias
Exercise 1
Using the following list, do the following:
[15, 70, 15, 38, 49, 98, 62, 89, 2, 21, 40, 74, 36, 36, 65, 1, 55, 16, 24, 56]
Exercise 2 (1 Point):
Using the following list, do the following:
1. Iterate through each element in the list
2. Print out whether the element is positive or negative or zero on a new line for each element.
[-2, 1, -2, 7, -8, -5, 5, 10, -6, 7]
Exercise 3 (2 Points):
Create a new list using the range function, appending the values from the range function's output into the list.
The range function must:
Hint: Use either a for loop or a list comprehension
Exercise 4 (6 Points):
In this exercise, you will be required to do the following:
Take the following phrase: The only thing we have to fear is fear itself
So, the end result should be:
Hetay onlyway hingtay eway avehay otay earfay isway earfay itselfway
In: Computer Science
Briefly write about your thoughts about Freedom of Speech on the Internet.
In: Computer Science
Can you think of a way that Excel can be used unethically and give an example?
Your answer must be a minimum of 2 paragraphs, no spelling errors, and complete sentences.
In: Computer Science
Which of the case studies that you read (Walmart, Target or 5 Big Data Industries) caught your attention and why? Before reading the articles, did you think about data being used in the manner that it is? Name one other organization that may be using data warehousing and data mining techniques and explain how it is being used. Or explain how after years of collecting data how the data in the Academic Database that was implemented in Modules 6 and 7 can be useful to the academic institution? Explain your answer in 100 to 150.
In: Computer Science
1.It is acceptable to let some else use your MSDSQ120 account if you are working close by in the lab. True or False
2. If I am a performing technical review on a plate map and I do not see a designated area for signature/initial and date, then the following is true: (choose the best response)
A. the plate map is exempt from my technical review
B. I only need to email the Originator of the plate map and say " I review the plate map"
C. I can apply my signature and date to the form.
D. I can apply my signature, date, and meaning of signature as "Reviewer" so that the purpose of my signature and date is clearly identify .
E. None of the above.
3. While in the lab, data should be recorded... ( Choose the best response)
A. On a scrap paper, then neatly written on the worksheet at the of the day.
B. Analyst should remember what happened in the lab with the assay and then record data at their desk.
C. While at the bench at the time each step is completed on the correct batch record.
4. Which examples below are acceptable format to document the date and time ( Choose best response)
a. 27Nov2020
b. 27Nov20
c. Nov 3, 2020
d. Nov3rd, 2020
e. January 3, 2020
f. All of the above
5. True or False : The date has been corrected according to Good Document Practices
(05Dec15) EE KAJ O6Dec15
6. True or False: We should record all data according to ALCOA documentation standards.
7. True or False : Recording data contemporaneously means that as long as it is recorded sometime during the day is acceptable.
8. True or False: Any pen is acceptable to use to record raw data as long as it is blue or black ink.
9. True or False : The date has been corrected according to Good Document Practices
(05Dec15) or 06Dec15EEKAJ 06Dec15
In: Computer Science
Show the major steps for computing X9 in “ADD X9, X10, X11” for the given values. Please indicate if there is an overflow and show the final content of X9 as a hexadecimal number. a) X10=0xCFFFFFFF and X11=0xC0000000 b) X10=0xCFFFFFFF and X11=0xA0000000
In: Computer Science
Convert 2.115 single-precision floating point binary format. Please show every single detail for upvote. Please do not answer otherwise.
In: Computer Science
Under normal conditions, commercial aircraft generally rise at
about 1,000 to 2,000
feet per minute (this is called the rate of climb) after take-off,
until they reach a
cruising altitude of 35,000 feet. Design the logic for a program
that allows the user to
enter the rate of climb as input, and then for every minute after
take-off until the
aircraft has reached cruising altitude, outputs the minute number,
and the height of the
plane after that minute. After that the program must output the
number of minutes that
have elapsed since take off, and the height at which the plane is
cruising (this may not
be exactly 35,000 feet).
In: Computer Science
Convert -10.5 single-precision floating point binary format.
Please show every single detail for upvote.
Please do not answer otherwise.
In: Computer Science