You need to assign the shifted value back to num using the assignment operator (num = num > 1). This also leads to the integer overflow error you're experiencing. So thats why the value of num remains unchanged, causing an infinite loop when num is greater than 0. ![]() You forgot to assign the shifted value back to the num variable within the while loop. Get the definition of the solution from Solve, renaming C1 as n for convenience, and explaining to Mathematica that n should be considered an integer. Since you're performing a bitwise AND operation with num and the result of the comparison, the value of (1 = 1) is 1, and you effectively perform num & 1 in each iteration of the loop. In C++, the result of a comparison operation is either 0 (false) or 1 (true). The bitwise AND operator (&) has lower precedence than the equality operator (=), so the expression is evaluated as (num & (1 = 1)). ![]() The integer overflow in your code is caused by the comparison (num&1 = 1)within the if statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |