[Question]
  [
In this challenge you will compute numbers from a curious sequence.
Your input is a single decimal nonnegative integer. Reverse the bits in this integer and then square the number to get the required output.
When reversing the bits you must not use any leading zeroes in the input. For example:
```
26 (base 10) = 11010 (base 2) -> 01011 (base 2) = 11 -> 11*11 = 121
```
The first 25 inputs/outputs of this sequence:
```
0: 0
1: 1
2: 1
3: 9
4: 1
5: 25
6: 9
7: 49
8: 1
9: 81
10: 25
11: 169
12: 9
13: 121
14: 49
15: 225
16: 1
17: 289
18: 81
19: 625
20: 25
21: 441
22: 169
23: 841
24: 9
```
Your solution should work for arbitrarily sized integers. If your language does not have a convenient built-in method of using those, implement your answer as if it does. You are then excused if your answer breaks for large numbers. However, do not use tricks/bounds that only work for a limited domain (such as a lookup table).
---
Your score is the number of bytes of source code.
**-50% bonus if you never convert the number to/from binary.** This is not limited to builtins, if you loop over the number bit by bit (either by shifting or masking or any other method), it will also count as conversion. *I don't know whether this is actually possible, but it gives an incentive to spot a pattern in the sequence.* 
Smallest score wins.
  
[Answer]
## Mathematica, ~~42~~ 21 bytes
*Thanks to alephalpha for halving the score.*
```
#~IntegerReverse~2^2&
```
The actual reason I did this in Mathematica was because I wanted to look at a plot... it sure looks funny:
[![enter image description here](https://i.stack.imgur.com/xseEC.png)](https://i.stack.imgur.com/xseEC.png)
[Answer]
# [Japt](https://github.com/ETHproductions/Japt), ~~29~~ ~~28~~ ~~11~~ 7 [bytes](https://en.m.wikipedia.org/wiki/ISO/IEC_8859)
(You can save the program as a 7-byte IEC\_8859-1-encoded file, then upload it to the [interpreter](http://ethproductions.github.io/japt).)
Japt is shortened JavaScript made by [ETHproductions](https://codegolf.stackexchange.com/users/42545/ethproductions).
```
¬¢w n2 ¬≤
```
[Try it online!](http://ethproductions.github.io/japt?v=master&code=oncgbjIgsg==&input=MjM=)
Explanation:
1. `¬¢` is shortcut to `Us2`, which compiles to `U.s(2)`. `U` is input (implicit), `.s(2)` called by a number, invokes `.toString(2)` (converts to binary, parses as string).
2. `w` compiles to `.w()`, which reverses the string (`.split('').reverse().join('')`).
3. `n2` works as `parseInt(<number>,2)`, i.e. converts binary to decimal.
4. `¬≤` invokes `Math.pow(<number>,2)`, i.e. squares the number.
[Answer]
## [Minkolang 0.14](https://github.com/elendiastarman/Minkolang), 43 bytes
Thanks to Mego for inspiring this.
```
n1{d1`,2$3*&$z2zd2%-2l$Md1%-;z2%*z2:{+}2;N.
```
[Test the code here](http://play.starmaninnovations.com/minkolang/?code=n1%7Bd1%60%2C2%243*%26%24z2zd2%25-2l%24Md1%25-%3Bz2%25*z2%3A%7B%2B%7D2%3BN%2E&input=22) and [check all test cases here](http://play.starmaninnovations.com/minkolang/?code=%28ndN1%7Bd1%60%2C2%243*%26%24z2zd2%25-2l%24Md1%25-%3Bz2%25*z2%3A%7B%2B%7DnN2%3BNlO%24I%29%2E&input=0%3A%200%0A1%3A%201%0A2%3A%201%0A3%3A%209%0A4%3A%201%0A5%3A%2025%0A6%3A%209%0A7%3A%2049%0A8%3A%201%0A9%3A%2081%0A10%3A%2025%0A11%3A%20169%0A12%3A%209%0A13%3A%20121%0A14%3A%2049%0A15%3A%20225%0A16%3A%201%0A17%3A%20289%0A18%3A%2081%0A19%3A%20625%0A20%3A%2025%0A21%3A%20441%0A22%3A%20169%0A23%3A%20841%0A24%3A%209).
### Explanation
This uses this recurrence relation:
```
a(0) = 0
a(1) = 1
a(2n) = a(n)
a(2n+1) = a(n) + 2^(floor(log_2(n))+1)
```
If `n` is the input, then `a(n)` is the resulting number after its binary sequence has been flipped. 0 and 1 are obvious. For `a(2n) = a(n)`, consider that `x0` (where `x` is any sequence of binary digits) flipped is `0x`, which is the same as `x`. For `a(2n+1)`, the reasoning is a bit more complicated. `x1` flipped is `1x`, which is equal to `x + 2^k` for some `k`. This `k` is one more than the number of digits in `x`, which is `floor(log_2(n))+1`. The full formula follows, except that it's modified a bit. This is what I actually code:
```
a(0) = 0
a(1) = 1
a(n) = a(n//2) + (n%2) * 2^(floor(log_2(n - n%2)))
```
As Mego and I worked out in chat, `floor(n/2) = (n - n%2)/2`. Thus, `log_2(floor(n/2))+1 = log_2(n - n%2)`. Furthermore, multiplying by `(n%2)` collapses both the odd and even parts into one expression.
Finally, without any further ado, here's the code, explained.
```
n                                              Take number from input
 1{                                            Start recursion that takes only one element
   d1`,                                        1 if top of stack 0 or 1, 0 otherwise
       2$3*                                    26
           &                                   Jump if top of stack is not zero
            $z                                 Store top of stack in register (z)
               
               zd2%-                           n - n%2
                    2l$M                       log_2(n - n%2)
                        d1%-                   floor(log_2(n - n%2))
              2             ;                  2^floor(log_2(n - n%2))
                             z2%               n%2
                                *              Multiply
                                 z2:           n//2
                                    {          Recurse
                                     +         Add
                                      }        Return
                                       2;N.    Square it, output as number, and stop.
```
[Answer]
# Python, 32 bytes
```
lambda x:int(bin(x)[:1:-1],2)**2
```
[Try it online.](http://ideone.com/r1Sx4H)
The code is pretty straightforward: `bin(6)`, for example, gives `0b110`, the binary representation of 6. `[:1:-1]` reverses the string and removes `0b`. `int` converts the string to an integer from binary, and `**2` squares it.
[Answer]
# [Par](http://ypnypn.github.io/Par/), 5 bytes
```
‚ú∂Œ£‚åêŒ£¬≤
```
That's read-binary-reverse-binary-square.
[Answer]
# [Jolf](https://github.com/ConorOBrien-Foxx/Jolf/), 7 bytes
[Just run it.](http://conorobrien-foxx.github.io/Jolf/#code=UUNfQmoy) The input on the page doesn't work.
```
^C_Bj22
```
## Explanation
```
^C_Bj22
    j   numeric input
   B    convert to binary (str)
  _     reverse
 C   2  parse as binary integer to base 10
^     2 square
        implicit output
```
---
I added the `Q` command, which makes this 6 bytes: `QC_Bj2`
[Answer]
# [TeaScript](https://github.com/vihanb/TeaScript), 9 [bytes](https://en.m.wikipedia.org/wiki/ISO/IEC_8859) ~~11~~
TeaScript is Javascript for golfing
```
¬Æx√∑v¬§)**2
```
Will golf more once I get back to my computer 
[Try it online!](http://vihanserver.tk/p/TeaScript/#?code=%22$p(%C2%AEx%C3%B7v%C2%A4)%C2%A4)%22&inputs=%5B%2211%22%5D&opts=%7B%22int%22:true,%22ar%22:false,%22debug%22:false,%22chars%22:false,%22html%22:false%7D)
[Test all](http://vihanserver.tk/p/TeaScript/#?code=%22r(25)m(%23%20%20$p(%C2%AEl%C3%B7v%C2%A4)%C2%A4)%20%20);%22&inputs=%5B%2211%22%5D&opts=%7B%22int%22:true,%22ar%22:false,%22debug%22:false,%22chars%22:false,%22html%22:false%7D)
[Answer]
## [Seriously](https://github.com/Mego/Seriously), ~~8~~ 7 bytes
```
2;,¬°R¬ø¬™
```
Challenges like these are perfect for Seriously :)
[Try it online](http://seriouslylang.herokuapp.com/link/code=323b2cad52a8a6&input=26)
Explanation:
```
2;,¬°    get a string representing the (decimal) input in binary, with a 2 on the bottom of the stack
R      reverse the string
¬ø    convert binary string to decimal int (using that extra 2 from earlier)
¬™      square it
```
[Answer]
# J, ~~10~~ 9 bytes
```
2^~|.&.#:
```
This is a tacit, monadic verb. [Try it online!](https://tio.run/nexus/j#@5@mYGulYBRXV6Onpqds9T81OSNfIU3JQCFTT8HI9D8A "J ‚Äì TIO Nexus")
*Thanks to @randomra for golfing off 1 byte!*
### How it works
```
2^~|.&.#:  Right argument: y
       #:  Convert y to binary.
   |.      Reverse the digits.
     &.    Dual; apply the inverse of #:, i.e., convert back to integer.
 ^~        Apply power (^) with reversed argument order (~)...
2          to 2 and the previous result.
```
[Answer]
## [Perl 6](http://perl6.org), 21 bytes
```
{:2(.base(2).flip)¬≤}
```
Example usage:
```
say {:2(.base(2).flip)¬≤}(26); # 121
say (0..24).map: {:2(.base(2).flip)¬≤};
# (0 1 1 9 1 25 9 49 1 81 25 169 9 121 49 225 1 289 81 625 25 441 169 841 9)
my &code = {:2(.base(2).flip)¬≤};
say code 3; # 9
say chars code 10¬π‚Å∞‚Å∞; # 140
```
[Answer]
# CJam, 10 bytes
```
ri2bW%2b_*
```
[Try it online](http://cjam.aditsu.net/#code=ri2bW%252b_*&input=17)
[Answer]
# JavaScript, ~~64~~ ~~63~~ ~~56~~ 53 bytes
```
n=>parseInt([...n.toString(2)].reverse().join``,2)**2
```
I realize I'm extra long, but hey, I can do it :P
[Demo](http://www.es6fiddle.net/ihkxrore)
[Answer]
# PHP, 45 bytes
```
echo pow(bindec(strrev(decbin($argv[1]))),2);
```
[Answer]
# Ruby, 35 bytes
```
->(x){x.to_s(2).reverse.to_i(2)**2}
```
[Answer]
# Shell, 25
```
dc -e2o?p|rev|dc -e2i?d*p
```
Input/output via STDIN/STDOUT:
```
$ echo 26|dc -e2o?p|rev|dc -e2i?d*p
121
$ 
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
bRCn
```
[Try it online!](https://tio.run/##yy9OTMpM/f8/Kcg57/9/IzMA "05AB1E ‚Äì Try It Online")
# Explanation
```
     Implicit input
b    Convert to binary
 R   Reverse
  C  Convert from binary
   n Square
     Implicit output
```
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 4 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
√†x√•¬≤
```
[Try it online.](https://tio.run/##DcurEYAwFEVBf6rJffmXgwEEDAZBORgaoARSWIjdmd2nc12Obe693Vd7vrd3hzA8gUgiU6hooJAhjwKKKKGMCqqYw8YxzGPhBw)
**Explanation:**
```
√†     # Convert the (implicit) input-integer to a binary-string
 x    # Reverse this string
  √•   # Convert it from a binary-string back to an integer
   ¬≤  # Take the square of this integer
      # (after which the entire stack joined together is output implicitly as result)
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 40 bytes
```
#+##&~Fold~Reverse@IntegerDigits[#,2]^2&
```
[Try it online!](https://tio.run/##Dcq9CsIwFIbhW/kgkMUj9sS/OigdRHAT1xAhaFoDtkIaXMTeejzDO71P7/Mz9D7Huy8t9kXNlNLT6f16TNfwCWkMzXnIoQvpGLuYR6vIuJvR5ZLikK3C/IDWKuegsWjwZYIhLAkrwpqwIWwJNWFH4EqSzwJYBAthMSyIRbEwFmeqX/kD "Wolfram Language (Mathematica) ‚Äì Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
b·πòB¬≤
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJi4bmYQsKyIiwiIiwiMTEiXQ==)
```
b·πòB¬≤
b·πòB  # Convert to binary, reverse, convert back to decimal
   ¬≤ # Square
```
[Answer]
# [Desmos](https://www.desmos.com), ~~124~~ 72 bytes
```
f(n)=total(mod(floor(n/2^l),2)2^k/2^l)^2
k=floor(log_2(n+0^n))
l=[k...0]
```
[Try it on Desmos!](https://www.desmos.com/calculator/veegjtgbcr)
*-52 bytes thanks to Aiden Chow*
[Answer]
# [Haskell](https://www.haskell.org), 38 bytes
```
(#0)
0#s=s^2
n#s=div n 2#(2*s+n`mod`2)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ0W0km5yQYFS7OI025ilpSVpuhY31TSUDTS5DJSLbYvjjLjygHRKZplCnoKRsoaRVrF2XkJufkqCkSZE9Y7cxMw8BVuFlHwuBYWCosy8EgUVhTQFIzOI9IIFEBoA)
[Answer]
# Pyth - 9 bytes
Straightforward conversions. I actually assigned 2 to a var which is pretty weird.
```
^i_jQK2KK
```
[Test Suite](http://pyth.herokuapp.com/?code=%5Ei_jQK2KK&test_suite=1&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A11%0A12%0A13%0A14%0A15%0A16%0A17%0A18%0A19%0A20%0A21%0A22%0A23%0A24%0A25%0A26&debug=0).
[Answer]
## Pyth, 9 bytes
```
^i_.BQ2 2
```
This is a very simple pyth based answer similar to the Python one
[Answer]
# ùîºùïäùïÑùïöùïü, 12 chars / 21 bytes
```
‚¶Ö`·∂Ä`+·¥ô(√Ø√ü2)¬≤
```
`[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter.html?eval=true&input=5&code=%E2%A6%85%60%E1%B6%80%60%2B%E1%B4%99%28%C3%AF%C3%9F2%29%C2%B2)`
## Noncompetitive answer, 9 chars / 18 bytes
```
‚¶Ö’Ö+·¥ô(√Ø‚ìë)¬≤
```
`[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter.html?eval=true&input=5&code=%E2%A6%85%D5%85%2B%E1%B4%99%28%C3%AF%E2%93%91%29%C2%B2)`
[Answer]
# TI-Basic (TI-84 Plus CE), 42 bytes
```
Prompt X
0‚ÜíS
While X
2S‚ÜíS
If X/2‚â†int(X/2
S+1‚ÜíS
End
S2
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 38 bytes
```
r;f(n){for(r=n%2;n/=2;r+=r+n%2);r*=r;}
```
Reverse all the bits, square the result. Pretty standard.
*-1 byte thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)!*
[Try it online!](https://tio.run/##HYvBCgIxDETv/YqwUEjsilLwYuyf7GVpqeRgVoJ4Wfbba@tcHsObyednzq0ZV1Ta62ZoSX1kvaTIFpKF3ojtlIyPJvqB1yqK300Kud1BzzgNIZDgyh0PiLfOEOjvR97WFxUnX@7gy6LTDDJDRSFid7Qf "C (gcc) ‚Äì Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 38 bytes
```
$_=(oct"0b".reverse sprintf"%b",$_)**2
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3lYjP7lEySBJSa8otSy1qDhVobigKDOvJE1JNUlJRyVeU0vL6P9/I5N/@QUlmfl5xf91fU31DAwN/usWAAA "Perl 5 ‚Äì Try It Online")
[Answer]
# Splunk (v8.2.6) Search Processing Language, 182 170 bytes:
```
|inputcsv b|foreach *[eval x=<<FIELD>>]|eval p=mvrange(0,floor(log(x,2)+1))|mvexpand p|eval x=floor(x/pow(2,p))%2|stats list(x) as x|eval x=tonumber(mvjoin(x,""),2),x=x*x
```
Big data. Smallish code.
Am learning Splunk for work, and decided to try to have a bit of fun with it.
Input is expected in a file at $SPLUNK\_HOME/var/run/splunk/csv/b.csv. The file must contain the number in base 10 followed by a newline. The output is the search result, which is analogous to an SQL `SELECT`. This is as close to our standard I/O rules as I could reasonably do in SPL, but I'm willing to work something out if this is problematic.
With whitespace:
```
| inputcsv b
| foreach * [eval x=<<FIELD>>] 
| eval p=mvrange(0,floor(log(x,2)+1))
| mvexpand p
| eval x=floor(x/pow(2,p))%2
| stats list(x) as x
| eval x=tonumber(mvjoin(x,""),2),x=x*x
```
Explanation (I plan to flesh this out more later):
```
| inputcsv b                            ``` Read in b ```
| foreach * [eval x=<<FIELD>>]          ``` Get the value into a field "x" (Splunk reads our "CSV" file in as an event with one field, named the value we want, with a value of the empty string.) ``` 
| eval p=mvrange(0,floor(log(x,2))+1)   ``` Create a multivalue field "p" which contains the numbers 0 to the number of bits required to represent our number, the order here also means we get the reverse for free ```
| mvexpand p                            ``` Expand our single event with a multivalue field "p" into multiple events, each with a certain value of p ```
| eval x=floor(x/pow(2,p))%2            ``` Calculate (x/(2**p))%2, and set that value back to x```
| stats list(x) as x                    ``` Collect the values of x back into a single multivalue event ```
| eval x=tonumber(mvjoin(x,""),2),x=x*x ``` Combine all the bits back into a string, and convert that string back into a numeric value, then square it```
```result is a single event with field x, containing the square of the bit reversed input.```
```
Edit: forgot how math works (ceil instead of floor + 1 for the bit length calculation), and managed to only check with inputs that worked with my wrong math. Also sort happened to be a leftover from when I was doing the problem more verbosely, we get the reverse sort for free. Nets to -12.
[Answer]
# [LOLCODE](http://lolcode.org/), 192 bytes
```
HAI 1.3
I HAS A s ITZ 0
I HAS A x
GIMMEH x
IM IN YR l
s R SUM OF PRODUKT OF s 2 MOD OF x 2
x R QUOSHUNT OF x 2
BOTH SAEM x 0,O RLY?
YA RLY
GTFO
OIC
IM OUTTA YR l
VISIBLE PRODUKT OF s s
KTHXBYE
```
[Try it online!](https://tio.run/##VY3LCsIwFET3@Yr5AJFawa2k9pFLm17NQ4xbdVfoIpv@fWwQBVdzZhg40zw95ucrJSUJu@1eEJS0kIggd0fx64voSOtGrUAaNCIYTCLCwHoNbnE2XPveZYwoobnOuKAUy3q6eLbKj@67VewUrGz02ooNwwzhKILMKTrXsmA6ZRF75@THdSVL1dD8i6LonbpVoUmpPLwB "LOLCODE ‚Äì Try It Online")
[Answer]
# [cQuents](https://github.com/stestoltz/cQuents), 10 bytes
```
K\rJ$)))^2
```
[Try it online!](https://tio.run/##Sy4sTc0rKf7/3zumyEtFU1Mzzuj/fyMzAA "cQuents ‚Äì Try It Online")
First time using cQuents.
## Explanation
```
    $      # Take the index.
   J )     # Convert to (default) base 2.
 \r   )    # Reverse it.
K      )   # Convert from (default) base 2 to base 10.
        ^2 # And square it.
```
]