Given a number N. You have to check whether every bit in the binary representation of the given number is set or not.
Example 1:
Input:
N = 7
Output:
1
Explanation:
Binary for 7 is 111 all the
bits are set so output is 1
Example 2:
Input:
N = 8
Output:
0
Explanation:
Binary for 8 is 1000 all the
bits are not set so output is 0.
Your Task:
You don't need to read input or print anything. Your task is to complete the function isBitSet() which takes an integer N as input parameters and returns 1 if all the bits in N's binary representation is set or return 0 otherwise.
Expected Time Complexity: O(1)
Expected Space Complexity: O(1)
Constraints:
0<=N<=100000

Source: geeksforgeeks | Difficulty: EASY
Tags: Bit manipulation

Data structures

Starter code: #User function Template for python3

class Solution:

    def isBitSet (self, N):

        # code here 

Solutions:
class Solution:

	def isBitSet(self, N):
		b = bin(N)[2:]
		for i in b:
			if i != '1':
				return 0
		return 1


class Solution:

	def isBitSet(self, N):
		if N == 0:
			return 0
		while N:
			if N & 1 == 0:
				return 0
			N >>= 1
		return 1


class Solution:

	def isBitSet(self, N):
		b = bin(N)[2:]
		k = str(b)
		if '0' in k:
			return 0
		else:
			return 1


import math

class Solution:

	def isBitSet(self, N):
		if N == 0:
			return 0
		N = N + 1
		t = math.log2(N)
		if math.ceil(t) == math.floor(t):
			return 1
		return 0


class Solution:

	def isBitSet(self, N):
		for l in bin(N)[2:]:
			if l == '0':
				return 0
		return 1


class Solution:

	def isBitSet(self, N):
		b = str(bin(N).replace('0b', ''))
		for i in b:
			if i == '0':
				return 0
		return 1


class Solution:

	def isBitSet(self, N):
		if N != 0:
			return int(N & N + 1 == 0)
		else:
			return 0


class Solution:

	def isBitSet(self, N):
		a = len(bin(N)[2:])
		b = bin(N)[2:].count('1')
		return 1 if a == b else 0


class Solution:

	def isBitSet(self, N):
		return 1 if N & N + 1 == 0 and N else 0


class Solution:

	def isBitSet(self, N):
		if not N:
			return 0
		return int(not N + 1 & N)


class Solution:

	def check(self, n):
		return n and (not n & n - 1)

	def isBitSet(self, N):
		if N == 0:
			return 0
		elif self.check(N + 1):
			return 1
		return 0


class Solution:

	def isBitSet(self, N):
		x = bin(N)[2:]
		y = str(x)
		z = len(y)
		res = 0
		while N:
			N = N & N - 1
			res += 1
		if z == res:
			return 1
		else:
			return 0


class Solution:

	def isBitSet(self, N):
		if bin(N)[2:].count('0') == 0:
			return 1
		return 0


class Solution:

	def isBitSet(self, N):
		s = bin(N).replace('0b', ' ')
		s = str(s)
		k = s.count('1')
		if len(s) - 1 == k:
			return 1
		return 0


class Solution:

	def isBitSet(self, N):
		if N == 1 or N == 0:
			return 0
		if N & N + 1 == 0:
			return 1
		return 0


class Solution:

	def isBitSet(self, N):
		if N == 0 or N == 1:
			return N
		a = format(N, 'b')
		if '0' in a and '1' in a:
			return 0
		return 1


import math

class Solution:

	def isBitSet(self, N):
		if N == 0:
			return 0
		num = int(math.log(N + 1, 2))
		if 2 ** num == N + 1:
			return 1
		else:
			return 0


class Solution:

	def isBitSet(self, N):
		s = bin(N)[2:]
		if '0' in s:
			return 0
		return 1


class Solution:

	def isBitSet(self, N):
		return int(not bin(N)[2:].count('0'))


class Solution:

	def isBitSet(self, N):
		s = '{0:b}'.format(N)
		if s.count('0') == 0:
			return 1
		return 0


class Solution:

	def isBitSet(self, N):
		l = str(bin(N))[2:]
		if N == 2 ** len(l) - 1:
			return '1'
		return '0'


class Solution:

	def isBitSet(self, N):
		l = list(str(bin(N)))
		l.pop(1)
		if N == 2 ** (len(l) - 1) - 1:
			return 1
		else:
			return 0


class Solution:

	def isBitSet(self, N):
		if N == 0:
			return 0
		elif N & N + 1 == 0:
			return 1
		return 0


class Solution:

	def isBitSet(self, N):
		if N > 2 and N & N + 1 == 0:
			return 1
		return 0


class Solution:

	def isBitSet(self, n):
		bi = bin(n).replace('0b', '')
		bi = str(bi)
		a = '0'
		b = '1'
		if bi == '0':
			return 0
		elif a in bi and b in bi:
			return 0
		return 1


class Solution:

	def isBitSet(self, n):
		if n & n + 1 == 0 and n > 0:
			return 1
		return 0


class Solution:

	def isBitSet(self, N):
		a = bin(N)
		b = a[2:]
		if '0' in b:
			return '0'
		else:
			return '1'


class Solution:

	def isBitSet(self, n):
		b = bin(n)
		b = b[2:]
		if '0' in b:
			return '0'
		else:
			return '1'


class Solution:

	def isBitSet(self, N):
		return int(set(bin(N)[2:]) == set(['1']))


class Solution:

	def isBitSet(self, N):
		N += 1
		i = 1
		while 2 ** i <= N:
			if 2 ** i == N:
				return 1
			i += 1
		return 0


class Solution:

	def isBitSet(self, N):
		b = bin(N).replace('0b', '')
		if b.count('1') == len(b):
			return 1
		else:
			return 0


class Solution:

	def isBitSet(self, N):
		b = bin(N)[2:]
		str_b = str(b)
		bits = []
		for i in str_b:
			bits.append(i)
		if '0' in bits:
			return 0
		return 1


class Solution:

	def isBitSet(self, N):
		bin = format(N, 'b')
		return 0 if '0' in bin else 1


class Solution:

	def isBitSet(self, N):
		return N & int(not N & N + 1)


class Solution:

	def isBitSet(self, N):
		l = []
		ans = bin(N)
		a = str(ans)
		p = a.replace('0b', '')
		for i in p:
			l.append(i)
		flag = 0
		for i in l:
			if i == '0':
				flag = 1
				break
		if flag == 0:
			return 1
		else:
			return 0


from math import log2

class Solution:

	def isBitSet(self, N):
		s = len(bin(N)[2:])
		return int(s == bin(N).count('1'))