Given a positive integer num, output its complement number. The complement strategy is to flip the bits of its binary representation. Please try on your own before reading on. Before solving this problem, we need to understand a few concepts in bitwise manipulation. XOR (^) Finding the complement of a number: So, apparently 5 → 101 Complement of…