[Question]
  [
**The Challenge**
Given an integer input `x` where `1 <= x <= 255`, return the results of powers of two that when summed give `x`.
**Examples**
Given the input:
```
86
```
Your program should output:
```
64 16 4 2
```
Input:
```
240
```
Output:
```
128 64 32 16
```
Input:
```
1
```
Output:
```
1
```
Input:
```
64
```
Output:
```
64
```
The output may contain zeros if the certain power of two is not present in the sum.
For example, input `65` may output `0 64 0 0 0 0 0 1`.
**Scoring**
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in each language wins.
  
[Answer]
# JavaScript (ES6), 28 bytes
```
f=n=>n?[...f(n&~-n),n&-n]:[]
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zTbP1i7PPlpPTy9NI0@tTjdPUydPTTcv1io69n9yfl5xfk6qXk5@ukaahoWZpiYXqpCRiQGGmCGGiJmJpuZ/AA "JavaScript (Node.js) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-2 since we may output zeros in place of unused powers of 2 :)
```
Ḷ2*&
```
**[Try it online!](https://tio.run/##y0rNyan8///hjm1GWmr///@3MAMA "Jelly – Try It Online")**
### How?
```
Ḷ2*& - Link: integer, n         e.g. 10
Ḷ    - lowered range of n            [  0,  1,  2,  3,  4,  5,  6,  7,  8,  9]
 2*  - two to the power of           [  1,  2,  4,  8, 16, 32, 64,128,256,512]
   & - bit-wise and                  [  0,  2,  0,  8,  0,  0,  0,  0,  0,  0]
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
BUT’2*
```
[Try it online!](https://tio.run/##y0rNyan8/98pNORRw0wjrf@H2x81rXH//9/CTEfByMRAR8FQR8HMBAA "Jelly – Try It Online")
### Explanation
BUT here is an explanation (note: I had assumed that we may only output the powers of 2 themselves and nothing else):
```
BUT’2* – Monadic link. Takes a number N as input. Example: 86
B      – Convert N to binary.                              [1, 0, 1, 0, 1, 1, 0]
 U     – Reverse.                                          [0, 1, 1, 0, 1, 0, 1]
  T    – Truthy indices.                                   [2, 3, 5, 7]
   ’   – Decrement.                                        [1, 2, 4, 6]
    2* – Raise 2 to that power.                            [2, 4, 16, 64]
```
**"Proof" that it works correctly.** The standard representation of an integer \$
X\$ in base 2 is a list \$\{x\_1, x\_2, x\_3,\cdots, x\_n\}\$, where \$x\_i\in\{0,1\},\:\forall\:\: i\in\overline{1,n}\$, such that:
$$X=\sum\_{i=1}^n x\_i\cdot 2^{n-i}$$
The indices \$i\$ such that \$x\_i=0\$ obviously have no contribution so we're only interested in finding those such that \$x\_i=1\$. Since subtracting \$i\$ from \$n\$ is not convenient (the powers of two all have exponents of the form \$n-i\$, where \$i\$ is any index of a \$1\$), instead of finding the truthy indices in this list we reverse it and then find them "backwards" with `UT`. Now that we've found the correct indices all we have to do is raise \$2\$ to those powers.
[Answer]
# Pure [Bash](https://www.gnu.org/software/bash/), 20
```
echo $[2**{7..0}&$1]
```
[Try it online!](https://tio.run/##TYvBCkBAGAbvnuJLy0Gt0IZSXkQO2F9cdrW7N3n2n5Qyx5lmnvzGq3UI5MMyecJu0CpUqkCJWnXQNsLD4XYTVsSJhuwRQ3zDWz0FSPmTTMtmIYYqy84mz4srFeXI2hpivgE "Bash – Try It Online")
### Explanation
```
          {7..0}     # Brace expansion: 7 6 5 4 3 2 1 0
       2**{7..0}     # Brace expansion: 128 64 32 16 8 4 2 1
       2**{7..0}&$1  # Brace expansion: 128&n 64&n 32&n 16&n 8&n 4&n 2&n 1&n (Bitwise AND)
     $[2**{7..0}&$1] # Arithmetic expansion
echo $[2**{7..0}&$1] # and output
```
[Answer]
# [Python](https://docs.python.org/), 35 bytes
```
lambda n:[n&2**i for i in range(8)]
```
Little-endian with zeros at unused powers of 2.
**[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPKjpPzUhLK1MhLb9IIVMhM0@hKDEvPVXDQjP2P0ioJLW4BCSqYWGmo2BkYqCjYKijYGaiacWloFBQlJlXogFSoaOgrmunrqOQBuZpArkxeeqa/wE "Python 3 – Try It Online")**
[Answer]
# [Sledgehammer](https://github.com/tkwa/Sledgehammer) 0.2, 3 bytes
```
⡔⡸⢣
```
Decompresses into `{intLiteral[2],call[NumberExpand,2]}`.
Sledgehammer is a compressor for Wolfram Language code using Braille as a code page. The actual size of the above is 2.75 bytes, but due to current rules on meta, padding to the nearest byte is counted in code size.
[Answer]
# [Catholicon](https://github.com/okx-code/Catholicon/), 3 bytes
```
ṫĊŻ
```
[Try it online!](https://tio.run/##S04sycjPyUzOz/v//@HO1Ue6ju7@/9/MFAA "Catholicon – Try It Online")
Explanation:
```
ṫ       Decompose         into the largest values where:
 Ċ               the input
  Ż       the bit count is truthy (equal to one)
```
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 7 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous tacit prefix function. Requires 0-based indexing (`⎕IO←0`).
```
2*⍸⍢⌽⍤⊤
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qG@qp/@jtgkG/420HvXueNS76FHP3ke9Sx51LfmfBhR/1NsHUdLVfGi98aO2iUBecJAzkAzx8Az@n6ZgYQYA "APL (Dyalog Extended) – Try It Online")
`2` two  
`*` raised to the power of  
`⍸` the **ɩ**ndices where true  
`⍢` while  
`⌽` reversed  
`⍤` of  
`⊤` the binary representation
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 3 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Ýo&
```
Port of [*@JonathanAllan*'s Jelly answer](https://codegolf.stackexchange.com/a/179178/52210), so make sure to upvote him!
Contains zeros (including -loads of- trailing zeros).
[Try it online](https://tio.run/##yy9OTMpM/f//8Nx8tf//DU0B) or [verify all test cases](https://tio.run/##yy9OTMpM/V9WeXiCvZLCo7ZJCgpK9v8Pz81X@6/zP9pQR8FIR8HQFIjNdBTMTIAYyLYAso1MDGIB).
**Explanation:**
```
Ý      # Create a list in the range [0, (implicit) input]
       #  i.e. 15 → [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
       #  i.e. 16 → [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
 o     # Take 2 to the power of each value
       #  → [1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768]
       #  → [1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536]
  &    # Bitwise-AND each value with the (implicit) input
       # 15 → [1,2,4,8,0,0,0,0,0,0,0,0,0,0,0,0]
       # 16 → [0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,0]
       # (and output the result implicitly)
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 17 bytes
```
#~NumberExpand~2&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7X7nOrzQ3KbXItaIgMS@lzkjtf0BRZl5JdJqDiVHsfwA "Wolfram Language (Mathematica) – Try It Online")
Mathematica strikes again.
[Answer]
# [R](https://www.r-project.org/), ~~27~~ 23 bytes
```
bitwAnd(scan(),2^(7:0))
```
[Try it online!](https://tio.run/##PYxNCsIwEIX3PcWAmxnQUEutIrrwIkJaEw3YSWmmtFJ69tgsdPM93g@vjxsYe91BaDSDY/GgwQ7ciPMMq3uZdwdigjh@AgbdGqg/YqDxAwtl9vob40RzOrns/olSiuZpibWT8cYPTDXStrjj8ZwTxSWzWB3WEzxViUWZJ9knVCXFLw "R – Try It Online")
### Unrolled code and explanation :
```
A = scan()         # get input number A from stdin
                   # e.g. A = 65
bitwAnd( A , 2^(7:0))  # bitwise AND between all powers of 2 : 2^7 ... 2^0 and A
                       # and implicitly print the result
                       # e.g. B = bitwAnd(65, c(128,64,32,16,8,4,2,1)) = c(0,64,0,0,0,0,0,1)
```
* 4 bytes thanks to @Kirill L.
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 29 bytes
Contains 5 unprintable characters.
```
n=>"€@ ".Select(a=>a&n)
```
# Explanation
```
//Lambda taking one parameter 'n'
n=>
//String with ASCII characters 128, 64, 32, 16, 8, 4, 2, and 1
"€@ "
//Iterate through all the chars of the above string and transform them to
.Select(a=>
//A bitwise AND operation between the integer value of the current char and the input value
a&n)
```
[Try it online!](https://tio.run/##Sy7WTS7O/O9Wmpdsk5lXouPpmleam1qUmJSTCuLb2SXZ/s@ztVM61OCgIMDBwsSopBecmpOaXKKRaGuXqJan@d@aKy2/SAOoViHT1sA6U1vbxsjU1FqTK7wosyTVJzMvVUOp2qDWSqG6WqHasFahtlZJRyFTR6G4pCgzL13PKz8zTwMooqSTpJGpqalpzfUfAA "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 39 bytes
```
f(n){for(;n;n&=n-1)printf("%d ",n&-n);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOi2/SMM6zzpPzTZP11CzoCgzryRNQ0k1RUFJJ09NN0/TuvZ/WX5mikKJBlBGIU9ToZqLE0mVrR1QIVDYmosTZJw1QjImTwnIreUC685NzMzTAOst0bAwAykr0TAyMYAwDCGUmQmEBonW/gcA "C (gcc) – Try It Online")
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 38 bytes
```
x=>{for(int y=8;y-->0;Print(x&1<<y));}
```
[Try it online!](https://tio.run/##Sy7WTS7O/O@YXJKZn2eTmVdip5CmYPu/wtauOi2/SAMooFBpa2FdqatrZ2AdUATka1SoGdrYVGpqWtf@t@ZK0zAyNNa0/g8A "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~16~~ 12 bytes
*-4 bytes thanks to Jonathan Allan*
```
*+&2**all ^8
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwX0tbzUhLKzEnRyHO4r81V3FpkkJZYk5parGGb6mCSpamQjWXAhAA1TuUWYOZunYKjnmVCirFCtVAMb2C0uIMKxCvVgOoHKIEpLSWiystv0jBwkzHyMRAx1DHzARsVHFipYKeWpqeGsQWoLr/AA "Perl 6 – Try It Online")
Returns an All Junction with 8 elements. This is a rather non-standard way of returning, but generally, Junctions can act as ordered (at least until autothreading is implemented) lists and it is possible to extract the values from one.
### Explanation:
```
*+&              # Bitwise AND the input with
   2**           # 2 raised to the power of
      all ^8     # All of the range 0 to 7
```
[Answer]
# 05AB1E, 7 bytes
```
2вRƶ<oò
```
explanation:
```
2в        convert input to binary array
R         reverse array
ƶ<        multiply each item by it's index and subtract 1
oò        2^item then round down
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f6MKmoGPbbPIPb/r/39AUAA "05AB1E (legacy) – Try It Online")
[Answer]
# [Julia 0.6](http://julialang.org/), 13 bytes
```
n->n&2.^(0:7)
```
[Try it online!](https://tio.run/##yyrNyUw0@59m@z9P1y5PzUgvTsPAylzzf25igQZQpKAoM68kJ08jTSNPU1Mn2sJMR8HIxEBHwVBHwcwkVvM/AA "Julia 0.6 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 29 bytes
```
(mapM(\n->[0,2^n])[7,6..0]!!)
```
[Try it online!](https://tio.run/##y0gszk7NyfmfZhvzXyM3scBXIyZP1y7aQMcoLi9WM9pcx0xPzyBWUVHzf25iZp6CrUJBUWZeiYKKQpqChdn/f8lpOYnpxf91kwsKAA "Haskell – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 25 bytes
```
->n{8.times{|i|p n&2**i}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6v2kKvJDM3tbi6JrOmQCFPzUhLK7O29n@0hZmOgpGJgY6CIZA2M4nVS01MzlCorqmoUSgoLSlWUFKurqi1UrJWSIuuiLUGi9X@BwA "Ruby – Try It Online")
[Answer]
# [C (clang)](http://clang.llvm.org/), 133 110 63 58 bytes
*58-byte solution thanks to @ceilingcat*.
```
x=256;main(y){for(scanf("%d",&y);x/=2;)printf("%d ",y&x);}
```
[Try it online!](https://tio.run/##S9ZNzknMS///v8LWyNTMOjcxM0@jUrM6Lb9Iozg5MS9NQ0k1RUlHrVLTukLf1shas6AoM68ELKqgpFOpVqFpXfv/v5GJIQA "C (clang) – Try It Online")
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 6 bytes
```
2*⍸⌽⊤⎕
```
2 to the `*` power of the `⍸` indices of the true bits of the `⌽` reversed `⊤` binary encoding of the `⎕` input
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qG@qp/@jtgkGXI862hXS/htpPerd8ahn76OuJUCp/0DB/2kKXBZmAA "APL (Dyalog Extended) – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 5 bytes
```
BPfqW
```
[Try it online!](https://tio.run/##y00syfn/3ykgrTD8/38LMwA "MATL – Try It Online")
# Explanation
Consider input `86` as an example.
```
B    % Implicit input. Convert to binary (highest to lowest digits)
     % STACK: [1 0 1 0 1 1 0]
P    % Flip
     % STACK: [0 1 1 0 1 0 1]
f    % Find: indices of nonzeros (1-based)
     % STACK: [2 3 5 7]
q    % Subtract 1, element-wise
     % STACK: [1 2 4 6]
W    % Exponential with base 2, element-wise. Implicit display
     % STACK: [2 4 16 64]
```
[Answer]
# Japt, ~~8~~ 5 bytes
```
Æ&2pX
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=xiYycFg=&input=ODY=)
```
Æ&2pX     :Implicit input of integer U
Æ         :Map each X in the range [0,U)
 &        :  Bitwise AND of U with
  2pX     :  2 to the power of X
```
---
## Alternative
Suggested by [Oliver](https://codegolf.stackexchange.com/users/61613/oliver) to avoid the `0`s in the output using the `-mf` flag.
```
N&2pU
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=TiYycFU=&input=ODYKLW1m)
```
N&2pU     :Implicitly map each U in the range [0,input)
N         :The (singleton) array of inputs
 &        :Bitwise AND with
  2pX     :2 to the power of U
          :Implicitly filter and output
```
[Answer]
# APL(NARS) 18 chars, 36 bytes
```
{(⍵⊤⍨8⍴2)/⌽1,2*⍳7}
```
test:
```
  f←{(⍵⊤⍨8⍴2)/⌽1,2*⍳7}
  f 86
64 16 4 2 
  f 240
128 64 32 16 
  f 1
1 
  f 64
64 
  f 3
2 1 
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
Ýoʒ›}æʒOQ
```
[Try it online!](https://tio.run/##yy9OTMpM/f//8Nz8U5MeNeyqPbzs1CT/wP//DU0B "05AB1E – Try It Online")
---
This is also correct for 6-bytes, but it doesn't complete in time on TIO for 86:
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
ÝoæʒOQ
```
[Try it online!](https://tio.run/##yy9OTMpM/f/fJ//wslOT/AP//7cwAwA "05AB1E – Try It Online")
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 12 bytes
```
{:T{2\#T&}%}
```
[Try it online!](https://tio.run/##S85KzP1fWPe/2iqk2ihGOUStVrX2f12w1n9DAwA "CJam – Try It Online")
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), ~~19~~ 16 bytes
-3 bytes thanks to ngn!
```
{*/x#2}'&|(8#2)\
```
[Try it online!](https://tio.run/##y9bNz/7/P82qWku/QtmoVl2tRsNC2Ugz5n@agoXZfwA "K (oK) – Try It Online")
oK does not have `power` operator, that's why I need a helper function `{*/x#2}` (copy 2 `x` times and reduce the resulting list by multiplication)
[Answer]
# [Alchemist](https://github.com/bforte/Alchemist), 125 bytes
```
_->In_x+128a+m
m+x+a->m+b
m+0x+a->n+a
m+0a->o+Out_b+Out_" "
n+b->n+x+c
n+0b+a->n+c
n+0a->p
o+b->o+c
o+0b->p
p+2c->p+a
p+0c->m
```
[Try it online!](https://tio.run/##JcwxCsMwDAXQ3acoWT8GN3TolL1Tj2Bsp9BAZRnigE8fRXYX6fG/UPil74e2vYp4u7yyb7jPzwAyhIZgF0JUuuGM0K1ivI/q45jTbTIZsdcNSeni/3hYVQz3mjVgLXtQMCfd@q/AqUjkcXKpG@dd7HoB "Alchemist – Try It Online") or [Test every input!](https://tio.run/##jY9Ba4MwFMfPzad4iK6V4NSMwtg67zt1h/Y2kJikUzAvmdohbPvs7mmh9LhL8uP/z/vxUsm@npQcdru1Qb2GApTT5l51OJVJ8YrlyHPxKLlllo9cJoXlFWG2MHI5M5Hj@/NQVssZQMCQV3M9ckWYVZfHCxN55ubaUeConAPPhaKbfJ5nRHaibRg7uQ4QGoRw05tPyCHM42fQjq32x8Pb8fASboyqHYQIP5A6P6SyVbWxTX9D1x/FbOW7BocTBNGDBogSIXqI@ncMZkMQfl@sTwn8UvIfdaKvdhDFXQ5Fqs1Xiue2pbGPznhIHGgzmM42SBONipl2aKZJbLd/ "Alchemist – Try It Online")
### Explanation
```
_->In_x+128a+m           # Initialize universe with input, 128a (value to compare to) and m (state)
m+x+a->m+b               # If c has been halved, subtract min(a, x) from a and x and put its value into b
m+0x+a->n+a              # If x < a, continue to state n
m+0a->o+Out_b+Out_" "    # Else print and continue to state o
n+b->n+x+c               # Add min(a, x) (i.e. x) back to x, and add it to c (we're collecting a back into c)
n+0b+a->n+c              # Then, add the rest of a to c
n+0a->p                  # Then, go to state p
o+b->o+c                 # Add min(a, x) (i.e. a) to c - x _is_ greater than a and so contains it in its binary representation, so we're not adding back to x
o+0b->p                  # Then, go to state p
p+2c->p+a                # Halve c into a
p+0c->m                  # Then go to state m
```
[Answer]
# [PHP](https://php.net/), ~~41~~ 39 bytes
```
for($c=256;$c>>=1;)echo$argv[1]&$c,' ';
```
[Try it online!](https://tio.run/##K8go@G9jXwAk0/KLNFSSbY1MzaxVku3sbA2tNVOTM/JVEovSy6INY9VUknXUFdSt////b2EGAA "PHP – Try It Online")
Or **38** with no fun `>>=` operator and PHP 5.6+:
```
for($x=8;$x--;)echo$argv[1]&2**$x,' ';
```
Or **36** with little-endian ("0 2 4 0 16 0 64 0") output:
```
while($x<8)echo$argv[1]&2**$x++,' ';
```
Really I just wanted to use the `>>=` operator, so I'm sticking with the **39**.
Tests:
```
$php pow2.php 86
0 64 0 16 0 4 2 0
$php pow2.php 240
128 64 32 16 0 0 0 0
$php pow2.php 1
0 0 0 0 0 0 0 1
$php pow2.php 64
0 64 0 0 0 0 0 0
$php pow2.php 65
0 64 0 0 0 0 0 1
```
[Answer]
# TSQL, ~~43~~ 39 bytes
Can't find a shorter fancy solution, so here is a standard loop.
-4 bytes thanks to MickyT and KirillL
```
DECLARE @y int=255
,@ int=128s:PRINT @y&@ SET @/=2IF @>0GOTO s
```
**[Try it out](https://data.stackexchange.com/stackoverflow/query/973160/sum-of-powers-of-2)**
]