Write a function that reverses the bits in an integer.

For example, the number `417` is `110100001` in binary. Reversing the binary is `100001011` which is `267`.

You can assume that the number is not negative.

Source: codewars | Difficulty: EASY
Tags: Bit manipulation

Fundamentals

Starter code: def reverse_bits(n):
	

Solutions:
def reverse_bits(n):
	return int(bin(n)[:1:-1], 2)


def reverse_bits(n):
	return int(f'{n:b}'[::-1], 2)


def reverse_bits(n):
	listbin = [bin(n)]
	listbin.sort(reverse=True)
	pleasework = list(''.join(listbin))
	comeonguy = ''.join(pleasework)
	almostanswer = comeonguy[:1:-1]
	answer = int(almostanswer, 2)
	return answer
	pass


def reverse_bits(n):
	return int(format(n, 'b')[::-1], 2)


def reverse_bits(n):
	return int(''.join(reversed(bin(n)[2:])), 2)


reverse_bits = lambda n: int(bin(n)[:1:-1], 2)


def reverse_bits(n):
	a = '{0:08b}'.format(n)
	b = list(a)
	b.reverse()
	c = ''
	for i in b:
		c += i
	return int(c, 2)