Code :- class Solution { public: int findComplement(int num) { int i = 0; // Initialize bit position counter int ans = 0; // Initialize the result for the complement while (num) { // Loop until all bits of num are processed // Check if the least significant bit (LSB) is 0 if ((num & 1) == 0) { // If LSB is 0, set the corresponding bit in the result to 1 ans = ans + (1 > 1; // Right shift num to process the next bit } return ans; // Return the computed complement } };