Given a number N, change all bits at even positions to 0.
Example 1:
Input: N = 30
Output: 10 
Explanation: Binary representation of 
11110. Bits at Even positions are 
highlighted. After making all of them 
0, we get 01010. Hence the answer is 10.
Example 2:
Input:  N = 10
Output: 10
Explanation: Binary representation of 
1010. Bits at Even positions are 
highlighted. After making all of them 
0, we get 1010. Hence the answer is 10.
Your Task:  
You dont need to read input or print anything. Complete the function convertEvenBitToZero() which takes n as input parameter and returns the value of N after changing bits at even positions.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1<= N <=(32-bit number)

Source: geeksforgeeks | Difficulty: EASY
Tags: Bit manipulation

Data structures

Mathematics

Starter code: #User function Template for python3
class Solution:
    def convertEvenBitToZero (ob, n):
        # code here 

Solutions:
class Solution:

	def convertEvenBitToZero(ob, n):
		num = 2863311530
		return num & n


class Solution:

	def convertEvenBitToZero(ob, n):
		bt = bin(n)[2:]
		ls = list(bt)
		st = ''
		for i in range(0, len(bt)):
			if len(ls) % 2 == 0:
				if i % 2 != 0:
					ls[i] = '0'
			elif i % 2 == 0:
				ls[i] = '0'
			st = st + ls[i]
		return int(st, 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		for i in range(32):
			if i % 2 == 0:
				if 1 << i & n > 0:
					n = n ^ 1 << i
		return n


class Solution:

	def convertEvenBitToZero(ob, n):
		t = format(n, 'b')
		res = ''
		if len(t) % 2 == 0:
			for i in range(len(t)):
				if (i + 1) % 2 == 0:
					res = res + '0'
				else:
					res = res + t[i]
			ans = int(res, 2)
			return ans
		else:
			for i in range(len(t)):
				if i % 2 == 0:
					res = res + '0'
				else:
					res = res + t[i]
			ans = int(res, 2)
			return ans


class Solution:

	def convertEvenBitToZero(ob, n):
		i = 0
		m = n
		while n > 0:
			i = i << 2
			i += 1
			n = n >> 2
		x = i & m
		return m ^ x


class Solution:

	def convertEvenBitToZero(ob, n):
		a = list(bin(n)[2:])
		for i in range(len(a) - 1, -2, -2):
			a[i] = '0'
		return int(''.join(a), 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		m = bin(n)[2:]
		if len(m) % 2 == 0:
			for i in range(len(m)):
				if i % 2 != 0:
					if m[i] == '1':
						m = m[:i] + '0' + m[i + 1:]
		else:
			for i in range(len(m)):
				if i % 2 == 0:
					if m[i] == '1':
						m = m[:i] + '0' + m[i + 1:]
		j = int(bin(int(m, 2)), 2)
		if j == 0:
			return n
		else:
			return j


class Solution:

	def convertEvenBitToZero(ob, n):
		num = bin(n)[2:]
		output = ''
		for i in range(len(num)):
			if i % 2:
				output += num[-i - 1]
			else:
				output += '0'
		return int(output[::-1], 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		bit = 0
		j = 1
		cnt = 0
		while j < n:
			j *= 2
			cnt += 1
		for i in range(cnt):
			if i % 2 == 0:
				if 1 << i & n > 0:
					n = n ^ 1 << i
		return n


import math

class Solution:

	def convertEvenBitToZero(ob, n):
		k = int(math.log2(n)) + 1
		i = 0
		while i <= k:
			n = n ^ n & 1 << i
			i = i + 2
		return n


class Solution:

	def convertEvenBitToZero(ob, n):
		return n & 715827882


class Solution:

	def convertEvenBitToZero(ob, n):
		s = 0
		for i in range(32):
			if i % 2 != 0 and (n >> i) % 2 != 0:
				s += 2 ** i
		return s


class Solution:

	def convertEvenBitToZero(ob, n):
		sub = 0
		m = 0
		x = n
		while x:
			if x & 1:
				sub += 1 << m
			m += 2
			x >>= 2
		return n - sub


class Solution:

	def convertEvenBitToZero(ob, n):
		n = bin(n)
		n = list(n)
		n.pop(0)
		n.pop(0)
		i = len(n) - 1
		while i >= 0:
			n[i] = '0'
			i -= 2
		n = ''.join(n)
		n = int(n, 2)
		return n


class Solution:

	def convertEvenBitToZero(ob, n):
		b = bin(n)[2:][::-1]
		res = ''
		for i in range(len(b)):
			if i % 2 == 0:
				res += '0'
			else:
				res += b[i]
		return int(res[::-1], 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		x = bin(n)
		arr = []
		for i in x[2:]:
			arr.append(i)
		arr = list(reversed(arr))
		for i in range(len(arr)):
			if i % 2 == 0:
				arr[i] = 0
		arr = list(reversed(arr))
		y = ''
		for i in arr:
			y += str(i)
		res = int(y, 2)
		return res


class Solution:

	def convertEvenBitToZero(ob, n):
		binary = list(format(n, 'b'))
		for i in range(-1, -len(binary) - 1, -2):
			binary[i] = '0'
		return int(''.join(binary), 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		even_mask = 12297829382473034410
		return n & even_mask


class Solution:

	def convertEvenBitToZero(ob, n):
		string = list(map(str, bin(n)[2:]))
		n = len(string)
		for i in range(n):
			if i % 2 == 0:
				string[n - i - 1] = '0'
		return int(''.join(string), 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		x = 0
		for i in range(1, 31, 2):
			x += pow(2, i)
		return n & x


class Solution:

	def convertEvenBitToZero(ob, n):
		b = list(bin(n))[2:]
		x = 0
		if len(b) % 2 == 0:
			x = 1
		for i in range(x, len(b), 2):
			b[i] = '0'
		b = ''.join(b)
		(decimal, i, n, b) = (0, 0, 0, int(b))
		while b != 0:
			dec = b % 10
			decimal = decimal + dec * pow(2, i)
			b = b // 10
			i += 1
		return decimal


class Solution:

	def convertEvenBitToZero(ob, n):
		n = n & 48038396025285290
		return n


class Solution:

	def convertEvenBitToZero(ob, n):
		x = bin(n)[2:]
		x = x[::-1]
		new = ''
		for i in range(len(x)):
			if i % 2 == 0:
				new += '0'
			else:
				new += x[i]
		new = new[::-1]
		return int(new, 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		s = str(bin(n)[2:].split())
		s = s[2:-2][::-1]
		op = ''
		for i in range(0, len(s)):
			if i % 2 == 0 and s[i] == '1':
				op += '0'
			else:
				op += s[i]
		op = op[::-1]
		ans = int(op, 2)
		return ans


class Solution:

	def convertEvenBitToZero(ob, n):
		bit = list(bin(n)[2:])
		p = len(bit)
		sum = 0
		if p % 2 == 0:
			for i in range(1, p, 2):
				if bit[i] == '1':
					bit[i] = '0'
			for i in range(p):
				sum = sum + int(bit[i]) * 2 ** (p - 1 - i)
		else:
			for i in range(0, p, 2):
				if bit[i] == '1':
					bit[i] = '0'
			for i in range(p):
				sum = sum + int(bit[i]) * 2 ** (p - 1 - i)
		return sum


class Solution:

	def convertEvenBitToZero(ob, n):
		a = bin(n)
		a = a[2:]
		if len(a) % 2 != 0:
			for x in range(0, len(a), 2):
				a = a[:x] + '0' + a[x + 1:]
		else:
			for x in range(1, len(a), 2):
				a = a[:x] + '0' + a[x + 1:]
		a = '0b' + a
		return int(a, 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		b = bin(n)[2:]
		r = ''
		b = b[::-1]
		for x in range(len(b)):
			if x % 2 == 0:
				r += '0'
			else:
				r += b[x]
		r = r[::-1]
		return int(r, 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		p = bin(n).replace('0b', '')
		no = 0
		l = list(p)
		k = len(l)
		l.reverse()
		for i in range(k):
			if i % 2 != 0 and int(l[i]) > 0:
				no = no + pow(2, i)
		return no


class Solution:

	def convertEvenBitToZero(ob, n):
		bits = []
		while n:
			bits.append(n % 2)
			n = n // 2
		sum = 0
		for i in range(len(bits)):
			if i % 2 != 0:
				sum += bits[i] * 2 ** i
		return sum


class Solution:

	def convertEvenBitToZero(ob, n):
		return n & 2863311530
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.convertEvenBitToZero(n))


class Solution:

	def convertEvenBitToZero(ob, n):
		l = bin(n)[2:]
		l = str(l)
		l = l[::-1]
		for i in range(0, len(l), 2):
			l = list(l)
			l[i] = '0'
		li = ''.join([str(elem) for elem in l])
		li = li[::-1]
		li = int(li, 2)
		return li
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.convertEvenBitToZero(n))


class Solution:

	def convertEvenBitToZero(ob, n):
		p = bin(n).replace('0b', '')
		no = 0
		l = list(p)
		k = len(l)
		l.reverse()
		for i in range(k):
			if i % 2 != 0 and int(l[i]) > 0:
				no = no + pow(2, i)
		return no
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.convertEvenBitToZero(n))


class Solution:

	def convertEvenBitToZero(ob, n):
		n = bin(n)
		n = n[:1:-1]
		p = ''
		i = 0
		while i < len(n):
			if i % 2 == 0:
				p = p + '0'
			else:
				p = p + n[i]
			i = i + 1
		p = p[::-1]
		return int(p, 2)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.convertEvenBitToZero(n))


class Solution:

	def convertEvenBitToZero(ob, n):
		s = bin(n)
		s = s[2:]
		d = len(s)
		c = d - 1
		k = 0
		if d % 2 == 0:
			for i in range(d):
				if i % 2 == 0 and s[i] == '1':
					k += 2 ** c
				c -= 1
			return k
		for i in range(d):
			if i % 2 == 1 and s[i] == '1':
				k += 2 ** c
			c -= 1
		return k


class Solution:

	def convertEvenBitToZero(ob, n):
		temp = 2863311530
		return n & temp


class Solution:

	def convertEvenBitToZero(ob, n):
		reduced_value = 0
		i = 0
		x = n
		while x:
			if x & 1:
				reduced_value += 2 ** i
			i += 2
			x >>= 2
		return n - reduced_value


def dectobin(a):
	res = ''
	while a > 0:
		d = a % 2
		res += str(d)
		a //= 2
	r = res[::-1]
	return r

def bintodec(s):
	r = 0
	n = len(s)
	d = 1
	for i in range(n):
		r += int(s[i]) * d
		d = d * 2
	return r

class Solution:

	def convertEvenBitToZero(ob, n):
		b = dectobin(n)
		b = b[::-1]
		a = ''
		for i in range(len(b)):
			if i % 2 == 0:
				a += '0'
			else:
				a += b[i]
		return bintodec(a)


class Solution:

	def convertEvenBitToZero(self, n):
		ans = 0
		i = 1
		while i < 32:
			ans |= 2 ** i & n
			i += 2
		return ans


class Solution:

	def convertEvenBitToZero(ob, n):
		if n == 11:
			return 10
		g = bin(n)
		g = str(g)
		g = list(g)
		g = g[2:]
		g = g[::-1]
		for i in range(0, len(g), 2):
			g[i] = '0'
		g = g[::-1]
		g = ''.join(g)
		return int(g, 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		j = list(str(bin(n).format('0b', '')))
		for i in range(len(j) - 1, -1, -2):
			j[i] = '0'
		res = ''
		res = res.join(j)
		return int(res, 2)


class Solution:

	def convertEvenBitToZero(ob, n):
		a = 1
		for i in range(0, 32, 2):
			mask = 1 << i
			n = n & ~mask
		return n