Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2120 pts I Given an integer, write a function Problem20 to determine if

ID: 3817685 • Letter: P

Question

Problem 2120 pts I Given an integer, write a function Problem20 to determine if it is a power of two. For example: the input integer is power of20ike 4,8,16.32, 64.... the retum value of function is 1 Problem20 If the input integer is not power of 2 (like 5,14,56,132,..., the return value of function Problem20 is 0 (Read ino and.h files carefully. Make sure your assembly code can make your whole project works) ll-- Exam Problem2.ino Minclude "Exami Problem2.h" #include "avrio.h" void setup0 uint8 t a 39; uint8 t b Problem2(a); Serial begin (9600); Serial println(b, DEC: void loop(0 ll- Examl Problem2.h #include extern "C" uint8 t Problem2(uint8 t):

Explanation / Answer

Logic:
If n is power of 2, Log2 n must be a whole number. so if we convert a log2(n) to integer and the result remains same as log2(n) in double representation we can say that that n is power of 2.

int problem(int n) {
    if ((int)(log(n)/log(2)) == log(n)/log(2))
       return 1;
    return 0;
}

NOTE: Please include the math.h header file

I hope you like the explanation and the short solution. Please let me know if you are still facing any trouble with the code. I shall be glad to help you with the code.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote