an HCL GUVI product

21. Count Set Bits

Required Input:

n = 29

Expected Output:

4

Code In Python

def count_set_bits(n): # Write your logic here pass n = 29 print(count_set_bits(n))

Run Code?

Click Run Button to view compiled output

22. Check if a Number Has Exactly One Set Bit

Required Input:

8

Expected Output:

True

Code In Python

def has_exactly_one_set_bit(n): # Write your logic here pass # Prefilled input n = 8 print(has_exactly_one_set_bit(n))

Run Code?

Click Run Button to view compiled output

23. Toggle the K-th Bit of a Number

Required Input:

n = 10
k = 2

Expected Output:

8

Code In Python

def toggle_kth_bit(n, k): # Write your logic here pass # Prefilled input n = 10 k = 2 print(toggle_kth_bit(n, k))

Run Code?

Click Run Button to view compiled output

24. Find Position of the Rightmost Set Bit

Required Input:

n = 18

Expected Output:

2

Code In Python

def rightmost_set_bit_position(n): # Write your logic here pass # Prefilled input n = 18 print(rightmost_set_bit_position(n))

Run Code?

Click Run Button to view compiled output

25. Check if Two Integers Have Opposite Signs

Required Input:

a = -10
b = 5

Expected Output:

True

Code In Python

def have_opposite_signs(a, b): # Write your logic here pass # Prefilled input a = -10 b = 5 print(have_opposite_signs(a, b))

Run Code?

Click Run Button to view compiled output

3 of 3