Write a program to print Binary representation of a given number N.
Example 1:
Input:
N = 2
Output:
000000000000000000000000000010
Explanation:
The binary representation of 2 is '10'
but we need to print in 30 bits so append
remaining 0's in the left.
Example 2:
Input:
N = 5
Output:
000000000000000000000000000101
Explanation:
The binary representation of 5 is '101'.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function getBinaryRep() which takes an Integer N as input parameter and returns a string of size 30 which is the binary representation of N.
Expected Time Complexity: O(LogN)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^9

Difficulty: EASY
Tags: Bit manipulation

Data structures
Skill types: Bit manipulation

Data structures
Expected Time Complexity: O(LogN)
Expected Auxiliary Space: O(1)

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

Solutions:
class Solution:

	def getBinaryRep(self, n):
		s1 = ['0' for i in range(30)]
		i = 0
		while n:
			if n & 1 == 1:
				s1[30 - i - 1] = '1'
			n >>= 1
			i += 1
		return ''.join(s1)


class Solution:

	def getBinaryRep(self, n):
		n = bin(n)
		length = len(str(n)) - 2
		new = ''
		n = str(n)
		for i in range(2, len(n)):
			new += n[i]
		if length == 30:
			return str(new)
		length_0 = 30 - length
		news = ''
		for i in range(length_0):
			news += '0'
		news += new
		return str(news)


class Solution:

	def getBinaryRep(self, n):
		x = format(n, 'b')
		op = '000000000000000000000000000000'
		new = op + x
		return new[len(x):]


class Solution:

	def getBinaryRep(self, n):
		bin = ''
		while n > 0:
			rem = n % 2
			bin = bin + str(rem)
			n = n // 2
		count = len(bin)
		prefix = '0' * (30 - count)
		bin = bin[::-1]
		res = prefix + bin
		return res


class Solution:

	def getBinaryRep(self, n):
		lt = []
		c = 0
		while n > 1:
			lt.insert(0, str(n % 2))
			c += 1
			n = n // 2
		lt.insert(0, str(1))
		c += 1
		for i in range(30 - c):
			lt.insert(0, str(0))
		return ''.join([s for s in lt])


class Solution:

	def getBinaryRep(self, n):
		s = ''
		while n != 0:
			rem = n % 2
			s = s + str(rem)
			n = n // 2
		return (30 - len(s)) * '0' + s[::-1]


class Solution:

	def getBinaryRep(self, n):
		change = format(n, 'b')
		bi = '000000000000000000000000000000'
		new = bi + change
		return new[len(change):]


class Solution:

	def getBinaryRep(self, n):
		b = ''
		while n != 1:
			b = str(n % 2) + b
			n = n // 2
		b = '1' + b
		b = b.zfill(30)
		return b


class Solution:

	def getBinaryRep(self, n):
		l = 30
		bn = ''
		div = l - 1
		while div > 0:
			if n - 2 ** div >= 0:
				n -= 2 ** div
				bn += '1'
			else:
				bn += '0'
			div -= 1
		if n % 2 == 1:
			return bn + '1'
		else:
			return bn + '0'


class Solution:

	def getBinaryRep(self, n):
		return '{:0>{bits}}'.format(str(bin(n))[2:], bits=30)


class Solution:

	def getBinaryRep(self, n):
		len = 30
		binary = ''
		i = 1 << len - 1
		while i > 0:
			binary += '1' if n & i else '0'
			i = i // 2
		return binary


class Solution:

	def getBinaryRep(self, n):
		str1 = ''
		while n > 0:
			str1 += str(n % 2)
			n = n // 2
		while len(str1) < 30:
			str1 += '0'
		return str1[::-1]


class Solution:

	def getBinaryRep(self, n):
		(temp, i, res) = (n, 30, ['0' for _ in range(30)])
		while temp != 0:
			res[i - 1] = str(temp % 2)
			temp //= 2
			i -= 1
		return ''.join(res)


class Solution:

	def getBinaryRep(self, n):
		k = n
		l = []
		while k > 0:
			l.append(k % 2)
			k = k // 2
		p = 30 - len(l)
		s = ''
		for i in range(p):
			s += '0'
		l.reverse()
		for i in l:
			s += str(i)
		return s


class Solution:

	def getBinaryRep(self, n):
		i = 1
		ans = 0
		rem = 0
		while n != 0:
			rem = n % 2
			ans = ans + rem * i
			n = n // 2
			i *= 10
		bit = '0' * (30 - len(str(ans)))
		return bit + str(ans)


class Solution:

	def getBinaryRep(self, n):
		size = 30
		b = bin(n).replace('0b', '')
		s_b = len(str(b))
		return '0' * (30 - s_b) + b


class Solution:

	def getBinaryRep(self, n):
		m = str(n)
		r = bin(n)[2:]
		k = r.zfill(30)
		return k


class Solution:

	def getBinaryRep(self, n):
		res = ''
		while n != 1:
			res += str(n % 2)
			n = n // 2
		res += '1'
		length = 30 - len(res)
		for i in range(length):
			res += '0'
		return res[::-1]


class Solution:

	def getBinaryRep(self, n):
		return bin(n).replace('0b', '').zfill(30)


class Solution:

	def getBinaryRep(self, n):
		binary = bin(n)[2:]
		string = '0' * (30 - len(binary))
		return string + binary


class Solution:

	def getBinaryRep(self, n):
		result = []
		for i in range(30):
			result.append(str(n & 1))
			n >>= 1
		return ''.join(result[::-1])


class Solution:

	def getBinaryRep(self, n):
		b = bin(n)[2:]
		return (30 - len(b)) * '0' + b


class Solution:

	def getBinaryRep(self, n):
		b = ''
		while n > 0:
			r = n % 2
			b = str(r) + b
			n = n // 2
		if len(b) < 30:
			p = '0' * (30 - len(b))
			b = p + b
			return b
		return b


class Solution:

	def getBinaryRep(self, n):
		return bin(n)[2:].zfill(30)


class Solution:

	def getBinaryRep(self, n):
		return '{0:030b}'.format(n)


class Solution:

	def getBinaryRep(self, n):
		res = ''
		num = bin(n)[2:]
		for i in range(1, 31 - len(num)):
			res += '0'
		return res + num


class Solution:

	def getBinaryRep(self, n):
		b = ''
		while n > 0:
			r = n % 2
			b += str(r)
			n = n // 2
		r = ''
		for i in range(30 - len(b)):
			r = r + str('0')
		return r + b[::-1]


class Solution:

	def getBinaryRep(self, n):
		res = str(format(n, 'b'))
		return (30 - len(res)) * '0' + res


class Solution:

	def getBinaryRep(self, n):
		res = ''
		for i in range(29, -1, -1):
			if n & 1 << i:
				res += '1'
			else:
				res += '0'
		return res


class Solution:

	def getBinaryRep(self, n):
		binary_str = ''
		while n > 0:
			if n % 2 == 1:
				binary_str = '1' + binary_str
			else:
				binary_str = '0' + binary_str
			n //= 2
		binary_str = '0' * (30 - len(binary_str)) + binary_str
		return binary_str


class Solution:

	def getBinaryRep(self, n):
		s = bin(n)[2:]
		s = str(s)
		s = s.rjust(30, '0')
		return s


class Solution:

	def getBinaryRep(self, n):
		b = '{0:b}'.format(n)
		s = str(b)
		c = s[::-1]
		while len(c) < 30:
			c += '0'
		d = c[::-1]
		return d


class Solution:

	def getBinaryRep(self, n):
		return bin(n).replace('0b', '0' * (32 - len(bin(n))))


class Solution:

	def getBinaryRep(self, n):
		a = []
		b = ''
		while n != 0:
			a.append(n % 2)
			n = n // 2
		while len(a) != 30:
			a.append(0)
		a.reverse()
		for i in a:
			b = b + str(i)
		return b


class Solution:

	def getBinaryRep(self, N):
		s = ''
		while N > 0:
			r = N % 2
			if r == 1:
				s = s + '1'
			else:
				s = s + '0'
			N = N // 2
		s = s[::-1]
		x = 30 - len(s)
		s = x * '0' + s
		return s


class Solution:

	def getBinaryRep(self, n):
		binary = ''
		ref = '0' * 32
		while n > 0:
			binary = str(n % 2) + binary
			n = n // 2
		return '0' * (30 - len(binary)) + binary


class Solution:

	def getBinaryRep(self, n):
		l = 30
		s = ''
		x = l - 1
		while x > 0:
			if n - 2 ** x >= 0:
				n -= 2 ** x
				s += '1'
			else:
				s += '0'
			x -= 1
		if n % 2 == 1:
			return s + '1'
		else:
			return s + '0'


class Solution:

	def getBinaryRep(self, n):
		cnt = 0
		n_bin = ''
		while n > 0:
			a = n % 2
			n_bin = str(a) + n_bin
			n = n // 2
			cnt += 1
		return '0' * (30 - cnt) + n_bin


class Solution:

	def getBinaryRep(self, n):
		res = ''
		i = 1 << 29
		while i > 0:
			if n & i != 0:
				res += '1'
			else:
				res += '0'
			i = i >> 1
		return res


class Solution:

	def getBinaryRep(self, n):
		(res, c) = ('', 0)
		while n != 0:
			if n % 2 == 0:
				res = '0' + res
			else:
				res = '1' + res
			c += 1
			n = n >> 1
		return '0' * (30 - c) + res


class Solution:

	def getBinaryRep(self, n):
		binary = ''
		while n > 0:
			binary += str(n % 2)
			n = n // 2
		bin_fin = ''
		for i in range(30 - len(binary)):
			bin_fin += '0'
		for i in range(len(binary)):
			bin_fin += binary[len(binary) - i - 1]
		return bin_fin


class Solution:

	def getBinaryRep(self, n):
		res = ''
		while n:
			res += str(n % 2)
			n = int(n / 2)
		res = res[::-1]
		length = len(res)
		if length < 30:
			temp = 30 - length
			res = '0' * temp + res
		return res


class Solution:

	def getBinaryRep(self, n):
		bin_num = bin(n)
		list_num = []
		for i in range(0, 32 - len(bin_num)):
			list_num.append('0')
		list_num.append(bin_num[2:])
		return ''.join(list_num)


class Solution:

	def getBinaryRep(self, n):
		self = 0
		a = format(n, 'b')
		op = '000000000000000000000000000000'
		self = op + a
		return self[len(a):]


class Solution:

	def getBinaryRep(self, n):
		s = bin(n)[2:]
		l = 30 - len(s)
		s1 = '0' * l
		return s1 + s


class Solution:

	def getBinaryRep(self, n):
		binar = format(n, 'b')
		binar = binar.zfill(30)
		return binar


class Solution:

	def getBinaryRep(self, n):
		a = []
		for i in range(0, 30):
			a.append('0')
		i = 0
		while n > 0:
			a[30 - 1 - i] = str(n % 2)
			n = n // 2
			i += 1
		a = ''.join(a)
		return a


class Solution:

	def getBinaryRep(self, n):
		st = '000000000000000000000000000000'
		l = bin(n)[2:]
		st = st + l
		return st[len(l):]


class Solution:

	def getBinaryRep(self, n):
		binary = bin(n).replace('0b', '')
		if len(binary) >= 30:
			return binary
		else:
			return '0' * (30 - len(binary)) + binary


class Solution:

	def getBinaryRep(self, n):
		ans = ''
		while n > 0:
			rem = n % 2
			ans += str(rem)
			n = n // 2
		rema = 30 - len(ans)
		for i in range(rema):
			ans += '0'
		return ans[::-1]


class Solution:

	def getBinaryRep(self, n):
		ans = ''
		while n > 0:
			rem = n % 2
			ans = str(rem) + ans
			n = n // 2
		if len(ans) < 32:
			temp = '0' * (30 - len(ans))
			return temp + ans


class Solution:

	def getBinaryRep(self, n):
		txt = bin(n)[2:]
		return txt.rjust(30, '0')


class Solution:

	def getBinaryRep(self, n):
		res = ''
		c = 0
		while n:
			res += str(n % 2)
			c += 1
			n //= 2
		ans = '0' * (30 - c)
		return ans + res[::-1]


class Solution:

	def getBinaryRep(self, n):
		(l, c) = ([], 0)
		while True:
			l.append(n % 2)
			n //= 2
			c += 1
			if c == 30:
				break
		l.reverse()
		string = ''
		for i in l:
			string += str(i)
		return string


class Solution:

	def getBinaryRep(self, n):
		l = ['0'] * 30
		j = 0
		ans = ''
		if n == 0:
			ans += '0'
		while n:
			ans += str(n & 1)
			n = n >> 1
		ans = ans[::-1]
		for i in range(30 - len(ans), 30):
			l[i] = ans[j]
			j += 1
		a = ''.join(l)
		return a


class Solution:

	def getBinaryRep(self, n):
		strn = ''
		a = bin(n).replace('0b', '')
		b = 30 - len(a)
		for i in range(b):
			strn += '0'
		return strn + a


class Solution:

	def getBinaryRep(self, n):
		an = bin(n)
		an = an[2:]
		k = 30 - len(an)
		return '0' * k + an


class Solution:

	def getBinaryRep(self, n):
		res = ''
		while n:
			res += str(n % 2)
			n = n // 2
		zero_str = ''
		res_len = len(res)
		for i in range(32 - res_len - 2):
			zero_str += '0'
		return zero_str + res[::-1]


class Solution:

	def getBinaryRep(self, n):
		a = bin(n)[2:]
		l = len(a)
		v = '0' * (30 - l)
		v = v + a
		return v


class Solution:

	def getBinaryRep(self, n):
		b = bin(n).replace('0b', '')
		l = len(b)
		v = '0' * (30 - l)
		v = v + b
		return v


class Solution:

	def getBinaryRep(self, n):
		x = format(n, 'b')
		o = '000000000000000000000000000000'
		n = o + x
		return n[len(x):]


class Solution:

	def getBinaryRep(self, n):
		s = ''
		for i in range(0, 30):
			x = n & 1
			if x:
				s = '1' + s
			else:
				s = '0' + s
			n >>= 1
		return s


class Solution:

	def getBinaryRep(self, n):
		n = bin(n)
		n = n[2:len(n)]
		a = len(n)
		a = 30 - a
		s = ''
		for i in range(0, a):
			s += '0'
		return s + n