34
3
So you are given a POSITIVE base 10 (decimal) number. Your job is to reverse the binary digits and return that base 10 number.
Examples:
1 => 1 (1 => 1)
2 => 1 (10 => 01)
3 => 3 (11 => 11)
4 => 1 (100 => 001)
5 => 5 (101 => 101)
6 => 3 (110 => 011)
7 => 7 (111 => 111)
8 => 1 (1000 => 0001)
9 => 9 (1001 => 1001)
10 => 5 (1010 => 0101)
This is a code-golf challenge, so the solution that uses the least bytes wins.
This is A030101 in the OEIS.
2
Does "reverse the bits" mean reverse its binary digits? Sometimes it can also mean invert every bit.
– ETHproductions – 2017-01-04T18:03:31.813Yes. Sorry for being unclear. – juniorRubyist – 2017-01-04T18:04:01.210
This and this are veeeeery similar. – Geobits – 2017-01-04T18:10:04.207
OEIS A030101. – orlp – 2017-01-04T18:12:07.103
1"base 10" Any particular reason why? – CalculatorFeline – 2017-06-21T01:00:08.587
Thought I found a really weird property, but 9 broke it. For all examples other than nine, if you reverse the binary number and multiply ones by their index and sum... Then you take that sum and get the "ath prime", it works for all of the numbers that result in primes. – Magic Octopus Urn – 2017-10-25T13:54:40.673