text:
Sum of Powers of 2
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, so the shortest answer in each language wins.

Does the list have to be sorted highest to lowest?

May we output some redundant zeros?

@Adám going to say yes this time. I want the output to be somewhat similar to the binary representation of the number. ie 65 = 0 + 2^6 +0 +0 +0 +0 + 0 +2^0

@JonathanAllan yes only if the zeros are present in the list in the same way that certain powers of two may not be present in the sum. For example, 65 may output 0 64 0 0 0 0 0 1 since those powers of two are not present in the sum.

RE: "sorted highest to lowest" why add a restriction that was not part of the challenge and invalidates most existing answers? (Also what about little-endian?!) + it invalidates my Python answer since sets do not have any order.

@JonathanAllan it was always part of the problem based on the output I provided, but I added that restriction explicitly after your question as I realized some may have been confused.

As it was written it said "Given an integer input x where 1 <= x <= 255, return the results of powers of two that when summed give x.". Note that it is a common misconception that test cases are to help define a challenge.

@JonathanAllan I've removed the restriction. I'll keep that in mind next time I post another question - I'm still fairly new to this. :)

I think you might want to state that any power of two may only be used once. Otherwise somebody could output "1 1 1" for the input 3.

Can the output be separated by newlines instead of spaces?

@SpookyGengar: you should probably say explicitly in the question that the output can be in any order.  I assumed from the test-case valid outputs that it had to be MSB to LSB, and only saw your comment while checking if an answer that isolated the lowest bit with n&-n was legal.

Is a leading zero in the output okay? i.e. 86 → [0, 64, 16, 4, 2]

JavaScript (ES6), 28 bytes
f=n=>n?[...f(n&~-n),n&-n]:[]

Try it online!

You're the only person in the whole world who can make me upvote JavaScript answers!

@sergiol, why wouldn't you normally upvote a JS solution? A good solution is a good solution regardless of the language used or who posted it.

@Shaggy Because Arnauld seems the only person to do such Javascript solutions. His answers are pure genius!

@sergiol Thanks for the compliment, but that's not quite true. I'm regularly outgolfed by more clever answers -- and that's what this site is all about. ^^

@Oliver I'm not sure. It seems like leading zeros (before 128) are forbidden. Otherwise, another possible variant is f=n=>n&&f(n&~-n)+[,n&-n].

Nice alternative. Although there was no mention of leading zeros, the OP did allow zeros in the output.

Jelly, 4 bytes
-2 since we may output zeros in place of unused powers of 2 :)
Ḷ2*&

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]

Jelly, 6 bytes
BUT’2*

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.

"ASCII-only" Sneaky ’ there...

@EriktheOutgolfer I guess BUT2*H would work though.

Pretty impressive that this works with an input of 302231454903657293676544.

Pure Bash, 20
echo $[2**{7..0}&$1]

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

Python, 35 bytes
lambda n:[n&2**i for i in range(8)]

Little-endian with zeros at unused powers of 2.
Try it online!

Catholicon, 3 bytes
ṫĊŻ

Try it online!
Explanation:
ṫ       Decompose         into the largest values where:
 Ċ               the input
  Ż       the bit count is truthy (equal to one)

Interesting! Get TIO'd :D

Works with 302231454903657293676544. Nice.

APL (Dyalog Extended), 7 bytesSBCS
Anonymous tacit prefix function. Requires 0-based indexing (⎕IO←0).
2*⍸⍢⌽⍤⊤

Try it online!
2 two
* raised to the power of
⍸ the ɩndices where true
⍢ while
⌽ reversed
⍤ of
⊤ the binary representation

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.

Huh! Neat little language, and all the characters are actually printable.

And now I can't get the Peter Gabriel song out of my mind...

05AB1E, 3 bytes
Ýo&

Port of @JonathanAllan's Jelly answer, so make sure to upvote him!
Contains zeros (including -loads of- trailing zeros).
Try it online or verify all test cases.
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)

... what?! Never honestly seen bitwise and used in osabie. Nice one.

@MagicOctopusUrn I indeed also don't use it very often. Can't even find any other answer I've used & in. xD I have used Bitwise-XOR a couple of times, like here or here and Bitwise-NOT once here (which I later removed again after golfing further..). I do use Bitwise-AND, XOR, OR, NOT, SHIFT, etc. pretty often in Java, but in 05AB1E not so much. :)

Wolfram Language (Mathematica), 17 bytes
#~NumberExpand~2&

Try it online!
Mathematica strikes again.

This also works with input of 302231454903657293676544.

C# (Visual C# Interactive Compiler), 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!

But we need to get rid of zeros, like n=>new int[8].Select((j,i)=>1<<i&n).Where(i=>i!=0) The part before Where is five bytes shorter btw

@polfosol The output may contain zeros

@JoKing Still, n=>new int[8].Select((j,i)=>1<<i&n) is 35 bytes long and we won't need additional flags and text encodings.

Using ascii characters 0-7 should be shorter, eg n=>"INSERT ASCII HERE".Select(a=>1<<a&n) But I'm on a mobile device that can't display or type unprintables, so I'll have to wait till I get home to update the answer

R, 27 23 bytes
bitwAnd(scan(),2^(7:0))

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.

23 bytes with bitwise and.

@KirillL.: brilliant !

C# (Visual C# Interactive Compiler), 38 bytes
x=>{for(int y=8;y-->0;Print(x&1<<y));}

Try it online!

aw, close :P

Fails for inputs 1, 2, 4, 8, 16, etc. (the x>y should be x>=y instead).

@ASCIIOnly - I'm telling you, the range operator is going to be sweet :)

@ASCII-only Mean while, you can use the flag /u:System.Linq.Enumerable and try this for 31 bytes

@EmbodimentofIgnorance sure. but i'd prefer not to list language as "C# /u:System.Linq.Enumerable" :P

C (gcc), 39 bytes
f(n){for(;n;n&=n-1)printf("%d ",n&-n);}

Try it online!

37 bytes

Perl 6, 16 12 bytes
-4 bytes thanks to Jonathan Allan
*+&2**all ^8

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

C (clang), 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!

In C89, you can declare like main(){} and the return type defaults to int.  Same for variables at global scope.  Also, at least on normal implementations like clang, printf and scanf work without prototypes.  You get warnings of course, but it's still valid C89 (maybe) or at least K&R C for them to be implicitly declared.  The types of the C objects you pass as args defines how they're passed, so a char* and int* will Just Work without truncating pointers to 32-bit on x86-64 or anything.  (Default argument promotions happen, same as for variadic functions which they are anyway.)

Or is this aiming to be valid C11 with no undefined behaviour?  If so, proudly proclaim it.  :)  And BTW, writing a function that takes an output array as an arg would probably be smaller.  Anyway, see Tips for golfing in C

You can use bitwise & to check if a bit is set.  Like y&(1<<x)&&printf("%d ",1<<x);.  Or to not skip zeros, just  printf("%d ", y&(1<<x)).  Or instead of counting bit positions, use x=256 and x>>=1 to shift the mask.   main(y){int x=256;for(scanf("%d",&y);x>>=1;)printf("%d ",y&x);} 63 bytes  Try it online! clang will even compile that with -std=c11

44 bytes

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!

Also works with input of 302231454903657293676544

Julia 0.6, 13 bytes
n->n&2.^(0:7)

Try it online!

Haskell, 29 bytes
(mapM(\n->[0,2^n])[7,6..0]!!)

Try it online!

Ruby, 25 bytes
->n{8.times{|i|p n&2**i}}

Try it online!

APL (Dyalog 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!

Japt, 8 5 bytes
Æ&2pX

Try it
Æ&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 to avoid the 0s in the output using the -mf flag.
N&2pU

Try it
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

Nice one. You can do N&2pU with -mf to avoid the 0s

MATL, 5 bytes
BPfqW

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]

05AB1E, 9 bytes
Ýoʒ›}æʒOQ

Try it online!

This is also correct for 6-bytes, but it doesn't complete in time on TIO for 86:
05AB1E, 6 bytes
ÝoæʒOQ

Try it online!

Both your answers output an empty set for 15, instead of [1,2,4,8]

@KevinCruijssen needed 2**0, nice catch. Ý over L.

Ah, I know the feeling. Also had L instead of Ý at first in my 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

using the bitwise and (&) you can save a few with the following ,@ int=128s:print @y&@ set @/=2IF @>0GOTO s.  This is hinted by @KirillL for the R answer

@MickyT that worked like a charm. Thanks a lot

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

K (oK), 19 16 bytes
-3 bytes thanks to ngn!
{*/x#2}'&|(8#2)\

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)

you can omit the { x}

@ngn Thanks! I tried it and it worked, but I wasn't sure it is acceptible.

CJam, 12 bytes
{:T{2\#T&}%}

Try it online!

PHP, 41 39 bytes
for($c=256;$c>>=1;)echo$argv[1]&$c,' ';

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

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! or Test every input!
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

Piet + ascii-piet, 88 bytes (4×22=88 codels)
My first Piet answer!
taqu ci?aqtqqiarufqqrNdsssec ?a??q??vejraimMdk??e lane???nv??rr ?Mddtqe ll esufnvsbiesue

In grid form:
taqu ci?aqtqqiarufqqrn
dsssec ?a??q??vejraimm
dk??e lane???nv??rr ?m
ddtqe ll esufnvsbiesue

As a PNG:

And with larger codels:

Try Piet online!
In my best attempt at pseudocode:
n=input+1
p=256
while p>=1
  {p=p/2
  if n>p
    {n=n-p
    print p}}

Python 2, 43 40 bytes
f=lambda n,p=1:n/p*[1]and f(n,p*2)+[p&n]

Try it online!

@JonathanAllan this definitely helped. Thanks for notifying me.

...and the restriction has been lifted, so -1 byte :)

PowerShell, 45 37 bytes
param($a)7..0|%{1-shl$_}|?{$_-band$a}

Try it online!
Takes input $a, loops from 7 to 0, each iteration performing a bit-shift left (-shl) to formulate the powers-of-two for each exponent. We then pull out those ? (where) the number $_ shares a value -binaryand with the input number.
-8 bytes thanks to mazzy

1-shl$_ instead '2*'*$_+'1'|iex?

@mazzy Oh, good call. I forgot we're dealing with numbers that work with -shl.

C# (Visual C# Interactive Compiler), 33 bytes
n=>{for(;n>0;n&=n-1)Print(n&-n);}

Port of @Arnauld's JavaScript (ES6) answer, so make sure to upvote him!
Try it online.
Explanation:
n=>{            // Method with integer parameter and no return-type
  for(;n>0      //  Continue looping as long as `n` is larger than 0:
      ;         //    After every iteration:
       n&=n-1)  //     Bitwise-AND `n` by `n-1`
    Print(      //   Print with trailing newline:
      n&-n);}   //    `n` bitwise-AND `-n`

Java 8, 46 bytes
n->{for(;n>0;n&=n-1)System.out.println(n&-n);}

Try it online.
Port of @Arnauld's JavaScript (ES6) answer, so make sure to upvote him!
Explanation:
n->{                     // Method with integer parameter and no return-type
  for(;n>0               //  Continue looping as long as `n` is larger than 0:
      ;                  //    After every iteration:
       n&=n-1)           //     Bitwise-AND `n` by `n-1`
    System.out.println(  //   Print with trailing newline:
      n&-n);}            //    `n` bitwise-AND `-n`

Breakthrough in Java: 36 chars, by using this rule. Let's go back 5 years and golf all Java answers ever produced!

@OlivierGrégoire Hmm, although I agree that it's most likely allowed, I'll pass tbh. I have used that rule when the input is for example an array, and we modify the input-array instead of returning a new one to save bytes. But adding an additional empty List argument just to store the output in to save byte with .add instead of System.out.println seems a bit cheaty imho.

Kind of like how Array.sort() doesn't actually return anything, it just modifies the input. That seems legit. In C# you can use void f(out int x) or void f(ref int x) to return the result, but that doesn't seem to help w/ golf in my experiments.

Perl 5, 22 bytes
say"@F"&2**$_ for 0..7

if newlines allowed as delimiter
22 bytes
28 bytes

Python 2, 36 bytes
def f(x):n=1;exec'print n&x;n*=2;'*8

Try it online!

QBasic, 62 60 bytes
INPUT n
t=2^n
WHILE n
IF t<=n THEN
?t
n=n-t
ENDIF
t=t/2
WEND

Here's a REPL, slightly expanded to not break QB.js's compiler...
How does it work?
INPUT n     gets the input
t=2^n       sets t to a power of 2, overshooting the first power of two
WHILE n     while we haven't fully deconstucted the input
IF t<=n THEN        if we found a power of two that is in this number
?t          then print it
n=n-t           and 'deconstruct' n by that amount
ENDIF
t=t/2       drop down to the next power of two and
WEND        repeat testing

Edit Saved 2 bytes, while n>0 is equivalent to while n.

JavaScript - 33 bytes
n=>[..."01234567"].map(i=>n&2**i)

32 bytes, Oliver's suggestion
n=>[...2**29+'4'].map(x=>n&2**x)

This appears to be 33 bytes, not 30. You can save a byte with this.

SAS, 91 bytes
data;input n;length o $99;z=1;do while(n);if mod(n,2) then o=z||o;n=int(n/2);z+z;end;cards;

Input is entered on separate lines after the cards; statement, like so:
data;input n;length o $99;z=1;do while(n);if mod(n,2) then o=z||o;n=int(n/2);z+z;end;cards;
86
240
1
64

Outputs a dataset with a string representation of the binary values in the o variable

Explanation:
data;
input n; /* Read a line of input */
length o $99; /* Output string (max of 99 characters) */
z=1; /* First power of 2 */
do while(n); /* While remainder is not 0 */
    if mod(n,2) then o=z||o; /* If current binary digit is 1, append power of two to start of output */
    n=int(n/2); /* Move to next binary digit */
    z+z; /* Double current power of two to get next power of two (add it to itself) */
end;
cards;
86
240
1

Wolfram Language 58 bytes
Flatten[2^#&/@(Position[Reverse@IntegerDigits[#,2],1]-1)]&

IntegerDigits[#,2] returns the binary representation of the input, #, as a list of 1's and 0's.
Reverse@ reverses that list.
(Position[...,1]-1) lists the positions of the 1's in the reversed list and decrements each position by 1.
2^#&/@ 2 is raised to the power of (position -1) for each integer in the list.
Flatten removes nested braces.

The sort-order restriction has been lifted (also you may have zeros in place of unused powers of 2 now, if that helps)

@JonathanAllan, Thanks, it saves 6 bytes.  There are no zeros generated by this approach.

Alchemist, 116 bytes
_->In_a+c
0f+a+0d->d
0f+a+d->e
0f+g->c
0_+0f+0g+0a+0d->f
0f+0g+0a+d->Out_c+Out_" "+f
f+e->f+a
f+c->f+2g
f+0c+0e+a->a

Try it online!
Uses a different approach to the existing Alchemist answer. Instead of counting back from 128, we count upwards, which can then support any positive input.
Explanation:
_->In_a          # Get input number of a atoms
       +c        # And initialise the power of 2
0f+a+0d->d       # Divmod the input by 2
0f+a+d->e

0f+0g+0a+d->Out_c+Out_" "+f    # If there is a remainder, print the current power of 2
0_+0f+0g+0a+0d->f              # Otherwise, do nothing

f+e->f+a         # Reset the number to the division by 2
f+0c+0e+a->a     # While the number is not zero, restart the loop

f+c->f+2g        # And double the power of 2
0f+g->c

x86-64 machine code, 12 bytes
This is a function you can call with the x86-64 System V calling convention, with this signature:
void binary_placevalues_withzero(uint8_t out[8] /*rdi*/,  uint8_t val /*sil*/);  or
void binary_placevalues_withzero(uint64_t *out  /*rdi*/,  uint8_t val /*sil*/); as a quick hack for making the output something you can print as one hex number for all 8 bytes.
It isolates the place values in increasing order into the output array, producing a result like 80 00 00 00 00 00 00 01 for esi = 129.
We start with mask = 1, and left-shift the mask by 1 until it overflows an 8-bit register.
nasm -l listing
    25 address   code bytes    global binary_placevalues_withzero
    26                         binary_placevalues_withzero:
    27 00000020 B101               mov  cl,1
    28                         .loop:
    29 00000022 88C8               mov  al,cl
    30 00000024 21F0               and  eax, esi     ; al,sil would cost a REX prefix
    31 00000026 AA                 stosb             ; *rdi++ = val & mask
    32 00000027 00C9               add  cl,cl        ; left-shift the mask
    33 00000029 73F7               jnc  .loop        ; until it shifts out
    34 0000002B C3                 ret

An alternate version that only writes non-zero entries (thus producing an output array of length __builtin_popcount(val)) is also 12 bytes.  This needs val zero-extended into ESI to avoid test false positives, unlike the version that doesn't skip zeros.
void binary_placevalues(uint8_t out[8] /*rdi*/,  unsigned val /*esi*/);
    11                         global binary_placevalues
    12                         binary_placevalues:
    13 00000010 B001               mov  al,1
    14                         .loop:
    15 00000012 85F0               test  eax, esi    ; ESI must have its high bits clear, so high garbage in EAX doesn't matter
    16 00000014 7401               jz   .skip
    17 00000016 AA                 stosb             ; store if the mask matches
    18                         .skip:
    19 00000017 00C0               add  al,al        ; left-shift the mask
    20 00000019 73F7               jnc  .loop
    21 0000001B C3                 ret
    22

As usual, ISA extensions that let us save instructions cost more code bytes: a BMI1 version is 14 bytes.  (https://www.felixcloutier.com/x86/BLSI.html and https://www.felixcloutier.com/x86/BLSR.html).  Very efficient, though: each of these BLSI/BLSR instructions is only 1 uop.
     1                         global binary_placevalues_bmi1
     2                         binary_placevalues_bmi1:
     3                         .loop:
     4 00000000 C4E278F3DE         blsi  eax, esi    ; bit lowest-set isolate:  n &-n
     5 00000005 AA                 stosb
     6 00000006 C4E248F3CE         blsr  esi, esi    ; bit lowest-set reset: (n-1) & n, and sets ZF according to the result.
     7 0000000B 75F3               jnz .loop
     8 0000000D C3                 ret

(If there was high garbage in ESI, this would keep going, storing 0 bytes when EAX held an isolated bit outside the low 8.)
If you wanted speed, with BMI2 pdep you'd use a 64-bit mask that deposited the low 8 bits at their corresponding position within each byte.  1 uop / 3 cycle latency on Haswell/Skylake, at the cost of a 10-byte instruction to create the mask. :P  But slow on Ryzen.

I'm not sure this is optimal.  I don't think manually implementing n & -n and so on with xor/sub/and and so on would be a win, though.

Hah! I wrote up a solution that did exactly that before I saw your answer. I pushed the results onto the stack, which was elegant, but meant I had to preserve and restore the return address (cost 2 bytes for push+pop) and also had to maintain a counter so the caller would know how many values to pop from the stack (cost 3 bytes for xor to zero + inc inside loop). Total was 20 bytes. That's about as good as it's going to get. All the instructions are 1 or 2 bytes. Might be able to shave off 2-4 bytes by taking a pointer to a pre-allocated buffer as an argument, like you did here.

@CodyGray: heh, that's fun.  If you pop the ret addr, jmp rsi is 2 bytes, same as push/ret.  But unbalances the return-address predictor stack, so in practice more instructions is better in this case.  I kind of glossed over returning a size for the versions that skip 0 elements.  The caller could pass a pre-zeroed buffer and treat the result as an implicit-length array (which works for my array-arg way, but not so much on the stack.  Well I guess you could push 0 / call.  But yeah, I was glad to find a fixed-length version with zeros so I didn't have to justify that or popcnt.

Vyxal, 3 bytes
ʀE⋏

Try it Online!
ʀE⋏
ʀ    # Range from zero to the input number, inclusive
 E   # Calculate 2 to the power of each list item (vectorized)
  ⋏  # Bitwise AND each list element with the input number

APL, 11 bytes
2*8-⍸⎕⊤⍨8⍴2

Explanation on example of number 86.
⎕ Input number: 86
⊤⍨8⍴2 Convert to bits: 0 1 0 1 0 1 1 0
⍸ Indexes of ones: 2 4 6 7
8- Substract from eight: 6 4 2 1
2* Powers of two: 64 16 4 2

This meets the specs of the challenge, but it appears that there may be unnecessary hard-coding here for the maximum number handled (255). This APL solution manages to print the powers of 2 in descending order without a hard-coded maximum, in 4 fewer bytes. Does that work in the flavor of APL that you use?

@Deadcode At least in Dyalog APL that would be ⌽2*⍸⌽2⊥⍣¯1⊢⎕. The behaviour of ⊤ is the reason why the other APL answers use the Extended variant

My solution written in classic APL with standard defaults and does not rely on specific dialect and/or ⎕IO←0 (index origin, default is ⎕IO←1).

Retina 0.8.2, 25 bytes
.+
$*
M!`(\G1|\1\1)*1
%`1

Try it online! Explanation:
.+
$*

Convert to unary.
M!`(\G1|\1\1)*1

Match as many powers of 2 as possible, and then an extra 1. This gives a total sum of the next power of 2. The regular expression is greedy (default), so tries to consume the largest possible power of 2 at each match. The M! then causes the matches themselves to be listed on separate lines.
%`1

Convert each line back to decimal.

Charcoal, 12 bytes
Ｉ⮌Ｅ⮌↨Ｎ²×ιＸ²κ

Try it online! Link is to verbose version of code. Includes zero values (+2 bytes to remove). Explanation:
     Ｎ          Input number
    ↨           Converted to base (MSB first)
      ²         Literal 2
   ⮌            Reversed (i.e. LSB first)
  Ｅ             Map over bits
        ι       Current bit
       ×        Multiplied by
          ²     Literal 2
         Ｘ      Raised to power
           κ    Current index
 ⮌              Reversed (back to MSB first)
Ｉ               Cast to string
                Implicitly print on separate lines

Apparently the restriction on output order has been removed, which means that the first ⮌ can be removed for a 1-byte saving.

Nice. This also works with an input of 302231454903657293676544.

Alchemist, 274 bytes
_->9a+In_x+s
s+a->s+b+c
s+x->s+y+z
s+0a+0x+b->b+d+m
s+0a+0x+0b->n+e
d+m->d+2n
d+0m->e
e+n->e+m
e+0n+b->d
e+0n+0b->h
h+m->h+u+v
h+0m->t
t+y+u->t
t+0y+u->f
t+y+0u->g+p
t+0y+0u->p
g+0p+z+v->g
g+0v->f
f+c->f+a
f+z->f+x
f+u->f
f+v->f
f+y->f
f+0v+0u+0z+0c+0y+a->s
p->Out_v+Out_" "

Try it online!
Ungolfed & Serialized
The algorithm is generating the powers of two from above, subtracting them from the input, check whether it's less or equal (output & decrement value in that case) or not and repeat while having enough copies of every value, to restore stuff (reading in Alchemist is pretty much destructive).
The "states" s0X can be merged, same with nxt without changing correctness of the program by combining all the zero-rules. The order of setting up copies or cleanup doesn't matter1:
_ -> 9a + In_x + s00

# Setup copies of x and a
s00 + a -> s00 + b + c
s00 + 0a -> s01
s01 + x -> s01 + y + z
s01 + 0x + b-> b+s1 + m
s01 + 0x +0b -> n+s2

# Compute power of
s1 +  m -> s1 + 2n
s1 + 0m -> s2

s2 +  n      -> s2 + m
s2 + 0n +  b -> s1
s2 + 0n + 0b -> s3

# Duplicate the power of two
s3 + m -> s3 + u+v
s3 +0m -> tst

# Check if it's below the value
tst +  y +  u -> tst
tst + 0y +  u -> nxt0                  # if not continue
tst +  y + 0u -> go + Out_v + Out_" "  # if not equal, output & continue
tst + 0y + 0u -> Out_v + Out_" "       # if equal, output

# Decrement the current value
go + z + v -> go
go + 0v -> nxt0

# Clear & restore for "next iteration"
nxt0 + c -> nxt0 + a  # restore counter
nxt0 + 0c->nxt1
nxt1 + z -> nxt1 + x  # restore current value (possibly decremented)
nxt1 + 0z -> nxt2
nxt2 + u -> nxt2      # clean up remainder of power of two ..
nxt2 + 0u -> nxt3
nxt3 + v -> nxt3      # .. and its copy
nxt3 + 0v -> nxt4
nxt4 + y -> nxt4      # clean up the rest of comparison
nxt4 + 0y + a -> s00

Try it online!
1: The way to read it is like this: The first atom on the left-handside encodes a state (to serialize control-flow), the other atoms are counters which are replaced by the right-handside.

explanation pls

@ASCII-only: Done :)

btw pls compress debug output, i.e. rule 100 times -> [rule] x 100

argh i keep getting close (read: i'm terrible at this)

145? m = halve, n = compare, o = restore x, p = refill d. a = value to compare to, b = value to compare a with to restore x, c = value to refill d with

also it would be nice to have better determinism detection, although it would probably be hard (better = counting rules that don't affect each other as deterministic)

deterministic 145?

granted, this takes advantage of the fact that max is 255

137?

better state change. EDIT: actually, 131?

128? can probably be golfed more

Order doesn’t matter, idk if that helps

Also wait they’re broken

Yeah 137, fix for 128 makes it 138

I’m sure you can make yours deterministic the same way I did, chaining instead of merging clears and possibly restoring x every time you decrement from y

@ASCII-only: That's a rather different algorithm (and way better golfed), probably you should post it as a separate answer.

134, still working on it, will post later

Pari/GP, 31 bytes
n->[2^i|i<-[0..n],bittest(n,i)]

Try it online!

MATL, 5 bytes
BXdXB

Try it online!
Explanation
B    % Convert to binary (as a vector)
Xd   % Give a diagonal matrix with the vector on its diagonal
XB   % Convert each row of the matrix to decimal

Nice result with 302231454903657293676544 working.

05AB1E, 6 bytes
bRεNo*

Try it online! or as Test Suite
Explanation
       # Implicit input n
b      # Convert to binary
 R     # Reverse
  ε    # For each digit d in the binary number
   N   # Push its index N
    o* # Compute d*2^N
       # Implicit output of list of results

F# (.NET Core), 41 bytes
fun x->Seq.map(fun y->x&&&pown 2 y)[0..7]

Try it online!

J, 13 bytes
(2^I.)&.|.@#:

Try it online!

Ruby, 26 bytes
->n{(0..7).map{|i|n&2**i}}

Try it online!
Same approach as Jonathan Allan's answer.

JS, 103 bytes
m=Math;f=a=>2**(m.floor(m.log2(a)));x=prompt()*1;y="";while(x>0&&x<256){z=f(x);y=y+" "+z;x=x-z}alert(y)

ArnoldC, 609 bytes
IT'S SHOWTIME
HEY CHRISTMAS TREE N
YOU SET US UP 0
GET YOUR ASS TO MARS N
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
HEY CHRISTMAS TREE I
YOU SET US UP 128
HEY CHRISTMAS TREE B
YOU SET US UP 0
STICK AROUND I
GET TO THE CHOPPER B
HERE IS MY INVITATION I
LET OFF SOME STEAM BENNET N
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE B
BULLSHIT
TALK TO THE HAND I
GET TO THE CHOPPER N
HERE IS MY INVITATION N
GET DOWN I
ENOUGH TALK
YOU HAVE NO RESPECT FOR LOGIC
GET TO THE CHOPPER I
HERE IS MY INVITATION I
HE HAD TO SPLIT 2
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

Try it online!
I apologise.

K (ngn/k), 26 bytes
{_0.5+`exp x*`ln 2}'*|=|2\

Try it online!
My first function-less K answer. Port of Xcoder's Jelly answer.
Explanation:
{_0.5+`exp x*`ln 2}'*|=|2\      Main program.
                        2\      Convert to base 2
                       |        Reverse
                      =         Group into falsey and truthy indices
                    *|          Select the second element (i.e. truthy indices)
                   '            For each of them
{                 }             Execute a function that
      `exp x*`ln 2              Raise the argument to the power of 2
 _0.5+                          Then round it

Regex (Perl / PCRE2 / Boost / Pythonregex), 16 13 bytes
x(x((?1))\2|)

Takes its input in unary, as the length of a string of xs. Returns its result as the list of matches (each is also a string of xs whose length is the value).
Try it online! - Perl
Try it online! - Perl (test cases only)
Try it online! - PCRE2
Try it online! - Boost
Try it online! - Python import regex
This is a power of 2 regex that I came up with just for this challenge. It's possible that nobody has ever seen this before, and either way it will be useful in other challenges (so far, Number of binary partitions). It needs absolutely no context, and can capture a power of 2 anywhere within a unary string. It doesn't use any special feature other than non-atomic recursion and a standard backreference.
x            # match += 1
(            # Define subroutine (?1)
    x        # match += 1
    ((?1))   # \2 = match made by recursive call; match += \2
    \2       # match += \2
|    # or
             # Match nothing, causing a cascading pop to the top level of
             # recursion, ending the match.
)

Note that while ((?R))\1|x (10 bytes) would theoretically greedily match powers of 2 with the same end result as the 13 byte regex presented above, regex engines throw an error instead of running it because the recursive path doesn't consume any characters before calling itself. Regex is designed to be guaranteed to halt in finite time, thus is given this rule much like the one where any loop with no upper limit on its iteration count will exit after making a zero-width match. So all the methods of matching powers of 2 using recursion or nested backreferences are stuck with using \$1+2+4+...+1\$ instead of \$1\times 2\times 2\times 2\times...\$
Also note that the non-atomic recursive regex presented above is not to be confused with the PCRE1 atomic recursive regex ^(x(?1)?x|x)$ (Try it online!), which can't be adapted to match the largest power of 2 that fits in the available space, because unless it matches exactly the entire string, it ends up matching seemingly arbitrary powers of 2. And to work on any other engine besides PCRE1, it must be modified, either as ^(x(?>(?1))?x|x)$ or ^x(x(?1)?+x|x)?$ to be explicitly atomic: Try it online!
Regex (PCRE2 / Ruby), 17 14 bytes
x(x(\g<1>)\2|)

Try it online! - PCRE2
Try it online! - Ruby
This is a straight port of the 13 byte recursive regex to Ruby's subroutine call syntax.
Regex (Perl / PCRE / .NET), 16 bytes
x((?(1)\1\1|x))*

Try it online! - Perl
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - .NET
This power of 2 matching is based on the regex ^(\1\1|^x)*x$ (Try it online!), which uses nested backreferences. But since it must be able to start its match anywhere inside the input, it can't make use of the ^ anchor. A (?(N)set|unset) conditional is used instead, to ensure the first iteration is seeded only once.
      # tail = input number; no need to anchor, as all positive inputs match
x             # tail -= 1; head += 1
(
    (?(1)     # Only allow the second alternative to match on the first iteration,
              # when \1 is unset, and the first alternative to match on every
              # subsequent iteration.
        \1\1  # \1 *= 2; tail -= \1; head += \1
    |
        x     # \1 = 1; tail -= \1; head += \1
    )
)*            # Iterate the above as many times as possible, minimum 0
              # Return match = head

Regex (Perl / Java / PCRE / .NET), 18 bytes
x(\1\1|(?!\2)x())*

Try it online! - Perl
Try it online! - Java
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - .NET
This is a port of the Perl/PCRE/.NET version, to regex engines that lack conditionals. An empty capture \3 is used to keep track of whether the loop has finished its first iteration.
            # tail = input number; no need to anchor, as all positive inputs match
x           # tail -= 1; head += 1
(
    \1\1    # This can only match on iterations other than the first, since \1 is
            # unset on the first iteration; \1 *= 2; tail -= \1; head += \1
|
    (?!\2)  # Only allow a match on the first iteration, when \2 is unset.
    x       # \1 = 1; tail -= \1; head += \1
    ()      # \2 = 0
)*          # Iterate the above as many times as possible, minimum 0
            # Return match = head

Regex (.NET), 19 bytes
(x(x?)(?<2>\2\2)*)*

Takes its input in unary, as a string of x characters whose length represents the number. Returns its output as the list of captures on the Balancing Group \1 stack, whose lengths represent the numbers.
Try it online!
(
    x         # \1 = 1
    (x?)      # \2 = 1 or 0; \1 += \2
    (?<2>     # Alias as capture group \2
        \2\2  # \2 = \2 * 2; \1 += \2
    )*        # Iterate the above as many times as possible, minimum zero
)*            # Iterate the above as many times as possible, minimum zero, on
              # each iteration pushing the capture onto the group \1 stack.

Unlike Calculate the prime factors, in this challenge, returning the output as a list of matches golfs better than pushing it onto the Balancing Group stack, even when we take advantage of .NET's ability to alias a capture group.
Without capture group aliasing, this golfs even worse. We can't use (x((?(2)\2\2|x))*)*, because when starting a new power of 2, \2 is already set and the first iteration won't be seeded with x. And it's not just a simple matter of clearing the \2 stack with a (?<-2>)*, because that attempts to loop a zero-width match and will stop after one iteration. So, patching this either results in the monstrosity (x((?(2)\2\2(?<-2>)|x))*(?<-2>)?)* (34 bytes): Try it online!, or, slightly better, (x((?(3)\2\2|x()))*(?<-3>)?)* (29 bytes): Try it online! This is in fact comparable to not even explicitly using Balancing Groups: (x(?=(.*))((?(?=\2)x|\3\3))*)* (30 bytes): Try it online!
Regex (ECMAScript / Python or better), 27 bytes
(?=.*?(((x+)(?=\3$))*x$))\1

Try it online! - ECMAScript
Try it online! - Perl
Try it online! - Java
Try it online! - PCRE
Try it online! - Boost
Try it online! - Python
Try it online! - Ruby
Try it online! - .NET
In regex flavors that lack both nested and forward-declared backreferences, an entirely different method of matching powers of 2 must be used: ^((x+)(?=\3$))*x$ (Try it online!). This is dependent on ending exactly at the end of the string, so the capturing of the power of 2 is done inside a lookahead.
        # tail = input number; no need to anchor, as all positive inputs match
(?=
    .*?                  # Decrease tail by the minimum necessary to match:
    (                    # \1 = largest power of 2 less than or equal to tail
        (
            (x+)(?=\3$)  # Assert tail is even; tail /= 2
        )*               # Iterate the above as many times as possible, minimum 0
        x$               # Assert tail == 1
    )
)
\1                       # Return \1 as the match

Regex (Perl / PCRE / Pythonregex / Ruby / .NET), 27 bytes
x((?=(\3)?)((?(2)\2\2|x)))*

Try it online! - Perl
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - Python import regex
Try it online! - Ruby
Try it online! - .NET
This is a port of the Perl/PCRE2/.NET version to regex engines lacking nested backreferences.
Although this version is of equal length to the ECMAScript one, it is of interest due to being much faster than it (and the recursive version) on regex engines that support it.
          # tail = input number; no need to anchor, as all positive inputs match
x                 # tail -= 1; head += 1
(
    (?=(\3)?)     # \2 = \3, or unset if \3 is unset
    (             # \3
        (?(2)     # Only allow the second alternative to match on the first
                  # iteration, when \2 is unset, and the first alternative to
                  # match on every subsequent iteration.
            \2\2  # \3 = \2 * 2; tail -= \3; head += \3
        |
            x     # \3 = 1; tail -= \3; head += \3
        )
    )
)*                # Iterate the above as many times as possible, minimum 0
                  # Return match = head

Regex (Perl / Java / PCRE / Pythonregex / Ruby / .NET), 29 bytes
x((?=(\3)?)(\2\2|(?!\4)x()))*

Try it online! - Perl
Try it online! - Java
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - Python import regex
Try it online! - Ruby
Try it online! - .NET
This is a combination of the no-nested-backreferences and no-conditionals ports, and again, the proviso applies about it being faster than the ECMAScript and recursive versions.

Chip -w, 115 bytes
H!ZZ--ZZZ--ZZZ--ZZZZ-Z-ZZZ-Z-ZZt
@^))e G>)e F>)e E>).d[DC].b[Bze
a,x]dc[(' b[('ca[L'`e'*sece'A]a
 H]--b['*fa['b^-['

Try it online!
Takes a single raw byte as input, and returns some mix of 128 64 32 16 8 4 2 1 and 000 00 00 00 0 0 0 0
In the TIO, the argument -wgNN will provide this program with a byte of value 0xNN. So, -wg5c provides 0x5c. The special value -wgkk will instead generate a random byte.
Chip is a 2D language where each element can interact with its four neighbors with single bit values only. An unsmooshed version of the above would look like this:
!ZZZ--ZZZ--ZZZ--ZZZ--ZZ--ZZ--ZZ--Zt
)))---))---))---))---)---)---)---)-e
|||H  ||G  ||F  ||E  |D  |C  |B  |A
xx)]d xx]d xx]d xx]d )]d x]d x]d x]d
xxx]c ))]c xx]c x)]c x]c )]c x]c x]c
x)x]b )x]b ))]b x)]b x]b x]b )]b x]b
)xx]a xx]a )x]a )x]a x]a x]a x]a )]a

s*f

Here we can see eight blocks, one for each power of two, from left to right. Each block contains a grid specifying which bits should be turned on for each character of that power. The input bits (capital letters) are connected as switches to control whether each digit should be its actual value, or zero.

x86 Machine Code, 20 bytes
; ECX is the input value ('x')
; EDX is a temporary, used for manipulations of 'x'
; EAX is a counter, which will also be the return value
; EBP is a temporary holding space for the return address

           GetSumOfPowersOf2:
5D            pop    ebp              ; save return address
31 C0         xor    eax, eax         ; counter = 0

           MainLoop:
89 CA         mov    edx, ecx         ; \
F7 DA         neg    edx              ; | temp = (x & -x)
21 CA         and    edx, ecx         ; /
52            push   edx              ; push temp onto stack
40            inc    eax              ; increment counter
89 CA         mov    edx, ecx         ; \
4A            dec    edx              ; | x = (x & (x - 1))
21 D1         and    ecx, edx         ; /
75 F1         jne    SHORT MainLoop   ; loop while x != 0

55            push   ebp              ; restore return address
C3            ret                     ; return to return address, with result in EAX

These bytes define a function, which takes as input a single 32-bit integer argument in the ECX register (the choice of which register to pass the input in is rather arbitrary, but ECX is the one used in the __fastcall calling convention). This is the value x from the question.
x is assumed to be non-zero, since it is given that 1 <= x <= 255. This allows us to only test the loop condition at the bottom of the loop.
The bulk of the code is a big ol' loop that calculates the powers of two using binary bit-twiddling and pushes them onto the stack. On x86, the PUSH instruction pushes a register value onto the stack and requires only 1 byte to encode, so it's a natural choice. The caller of this function will then just retrieve the return values by POPing them off the stack. Although this is a non-standard convention (by convention, a function's result is either returned in a register or stored into a memory address via a pointer), it works.
Well, as long as you attend to one little detail: the fact that the CALL instruction pushes the return address onto the stack, and the fact that the RET instruction knows where to return by popping the return address pushed onto the stack by the CALL instruction. So, if we want to return values on the stack, we need to preserve the return address at the top of the function. This is done by POPing the value at the top of the stack into the EBP register for safe-keeping, PUSHing the return values onto the stack during the loop, and then PUSHing the value in EBP (the preserved return address) onto the stack at the position where the RET instruction will expect to find it.
With this arrangement, when control returns to the caller, all they'll have to do is POP off the return values. Of course, they need to know how many values to pop off the stack, so we have to maintain a counter inside of the loop. The EAX register was chosen for this counter, since in all x86 calling conventions, functions return their result in the EAX register. This function returns as its result the number of values to pop off of the stack.
The caller would do something like this to exercise the function:
    mov   ecx, 86             ; put input value ('x') into ECX for passing to function
    call  GetSumOfPowersOf2   ; call the function
    mov   ecx, eax            ; save the function's return value (number of values to pop off stack)
GetAndPrint:
    pop   eax                 ; pop value off of stack into EAX
    call  PrintValueInEAX     ; print the value stored in EAX
    dec   ecx                 ; decrement counter
    jnz   SHORT GetAndPrint   ; loop while counter != 0

Pushy, 9 bytes
oBL:K2*#.

Try it online!
oB         \ Push binary digits to stack (least significant bit at the top).
  L:       \ len(stack) times do:
    K2*    \     Multiply all items by 2
       #.  \     Pop and print the top item

Desmos, 55 bytes
f(n)=2^{b[mod(floor(n/2^b),2)=1]}
b=[0...floor(log_2n)]

Port of Mr. Xcoder's Jelly answer.
Try it on Desmos!

Thunno 2, 4 bytes
LOÆ&

Attempt This Online!
Port of Jonathan Allan's Jelly answer.
Explanation
LOÆ&  # Implicit input  ->  10
L     # Lowered range   ->  [0,1,2,3,4,5,6,7,8,9]
 O    # Two power       ->  [1,2,4,8,16,32,64,128,256,512]
  Æ&  # Bitwise AND     ->  [0,2,0,8,0,0,0,0,0,0]
      # Implicit output

Uiua, 9 bytes
ⁿ:2▽:⇡⧻.⋯

⋯ get the bit representation as a list
⇡⧻. make a list of the same length, counting up from 1 [1, 2, ...]
▽: keep the values from the incrementing list for which there is a truthy bit in the bit representation list
ⁿ:2 2^n


text:
Trapped Knight Sequence
Introduction
Inspired by the very recent video The Trapped Knight - Numberphile, I came up with a challenge.
The trapped knight sequence is a finite integer sequence of length 2016, starting from 1, and has the following construction rules:

Write a number spiral in the following manner:

17 16 15 14 13 ...
18  5  4  3 12 ...
19  6  1  2 11 ...
20  7  8  9 10 ...
21 22 23 24 25 ...

Place a knight on 1.
Move the knight to the grid with the smallest number it can go that has not been visited before, according to the rules of chess (i.e. 2 units vertically and 1 unit horizontally, or vice versa).
Repeat until the knight gets stuck.

Here is the first three steps:
Step 1
 17  [16]  15  [14]  13
[18]   5    4    3  [12]
 19    6  < 1>   2   11
[20]   7    8    9  [10]
 21  [22]  23  [24]  25

Possible moves are 10, 12, 14, 16, 18, 20, 22, 24, among which the smallest is 10, so the second term is 10.
Step 2
  4  [ 3]  12  [29]  54
( 1)   2   11   28  [53]
  8    9  <10>  27   52
[23]  24   25   26  [51]
 46  [47]  48  [49]  50

Possible moves are 1, 3, 23, 29, 47, 49, 51, 53, among which the smallest is 3, so the third term is 3.
Step 3
 35  [34]  33  [32]  31
[16]  15   14   13  [30]
  5    4  < 3>  12   29
[ 6] ( 1)   2   11  [28]
  7  [ 8]   9  (10)  27

Possible moves are 6, 8, 10, 16, 28, 30, 32, 34, among which the smallest is 6, so the fourth term is 6.
The sequence stars with:
1 10 3 6 9 4 7 2 5 8 11 14 ...

and ends with
... 2099 2284 2477 2096 2281 2474 2675 2884 3101 2880 2467 2084

Challenge
Write a shortest program or function, receiving an integer in the range [1, 2016] (or [0, 2015] if 0-indexed is used) as input, output the number at that index in the trapped knight sequence. You can choose to index the sequence with 0-indexed or 1-indexed, but you must specify which indexing scheme you use.
Test cases (1-indexed)
n    | s(n)
-----+-----
   1 |    1
   2 |   10
   3 |    3
   6 |    4
  11 |   11
  21 |   23
  51 |   95
 101 |   65
 201 |  235
 501 |  761
1001 | 1069
2001 | 1925
2016 | 2084
For all possible outputs, please refer to this page.
Winning Criteria
The shortest code of each language wins. Restrictions on standard loopholes apply.

Very closely related

@Arnauld That question was inspired by mine (as indicated), only being faster to go main. Also, this sequence is finite, so some aspects in golfing may be different in that sense.

The other sequence is also finite, stopping at square 12851850258

@JoKing Well, but because this stops quite quickly, I'd like to see answers in esolangs with smaller integer ranges (are there any esolangs implementing 16-bit integers?)

I voted to close. If answers from the other question can be copied to this one while only altering a single or two bytes, then the questions are too similar. I'm sorry that the other question got posted before this one but that's the fastest gun in the west effect

Well, If this question was posted first in the sandbox, that doesn't means the dupe would be the other question?

@LuisfelipeDejesusMunoz I have asked that exact question in chat

@BassdropCumberwubwubwub relevant: https://codegolf.meta.stackexchange.com/questions/1875/closing-old-question-as-duplicate-of-a-new-one

JavaScript (ES7),  182  181 bytes
f=(n,[x,y]=[2,1],a=[...Array(4e3)].map((_,n)=>[1,-1].map(s=>(i&1?-s:s)*(i+s*n-(n>0?n:-n)>>1),i=n**.5|0,n-=i*++i)))=>n--?f(n,a.find(([X,Y],j)=>(i=j,(x-X)*(y-Y))**2==4),a,a[i]=[]):i+1

Try it online!
How?
A slightly modified version of my answer to the The Path Of The Wildebeest is definitely shorter (and faster) than that. But I wanted to try a different approach. Incidentally, I think it might be easier to implement this method in some esolangs.
Algorithm:

Initialization: we build the full list of coordinates for the first 4000 squares of the spiral, which is enough to process all moves of the knight before it gets trapped (the highest reached square being \$3199\$).
We look for the first square \$(X,Y)\$ such that:
$$((x-X)\times(y-Y))^2=4$$
where \$(x,y)\$ are the current coordinates of the knight.
The above condition is true only if \$|x-X|=1\$ and \$|y-Y|=2\$, or \$|x-X|=2\$ and \$|y-Y|=1\$, which covers all possible knight moves.
We set \$(x,y)=(X,Y)\$ and invalidate the entry in the list so that it's not picked a second time.
We either restart at step 2 or return the last index that was found if we're done.

Node.js, 155 bytes
n=>(g=(x,y)=>n--?g(Buffer('QHUbcdWJ').map(m=c=>g[i=4*((x+=c%6-2)*x>(y+=c%7-2)*y?x:y)**2,i-=(x>y||-1)*(i**.5+x+y)]|i>m||(H=x,V=y,m=i))|H,V,g[m]=1):m+1)(1,2)

Try it online!

05AB1E, 53 bytes
Xˆ0UF2D(Ÿ0KãʒÄ1¢}εX+}Dε·nàDtyÆ+yO·<.±*->}D¯KßDˆkèU}¯θ

Exact port of my 05AB1E answer for The Path of the Wildebeest challenge, except with the 3 replaced with a 2, and a trailing θ is added to output the 0-indexed value instead of the entire sequence of the first \$n+1\$ items.
Try it online or verify some more test cases (times out for the largest test cases).
Explanation:
See the explanation in my linked The Path of the Wildebeest answer. The only modified parts are the:
2D(Ÿ    # Get a list in the range [-2,2]: [-2,-1,0,1,2]

and a trailing:
θ       # Only leave the last item of the list

EDIT: A port of @Arnauld's approach in his JavaScript (ES7) answer is (currently):
05AB1E, 57 56 bytes
0D‚DˆUF64D(ŸãΣ·nàDtyÆ+yO·<.±*->}©ʒX-Pn4Q}¯¡˜2£DˆU}®J¯Jk>θ

Try it online or verify some more test cases (times out for the largest test cases).
Explanation:
‚%                # Create a pair of zeros: [0,0]
                  # (by pairing the (implicit) input with itself,
                  #  and then using modulo (implicit) input)
  DˆU             # Set both variable `X` to this, and add it to the global_array
F                 # Loop the (implicit) input amount of times:
 64D(Ÿ            #  Create a list in the range [-64,64]
      ã           #  Create each possible pair of `x,y`-coordinates
       Σ·nàDtyÆ+yO·<.±*->}
                  #  Sort this list in a spiral
        ©         #  Save it in the register (without popping)
 ʒ      }         #  Filter the list of coordinates by:
  X-              #   Subtract the coordinate of variable `X`
    P             #   Take the product
     n            #   Take the square
      4Q          #   Check if its equal to 4
                  # Since 05AB1E cannot remove inner lists, we use a workaround:
         ¯¡       # Split this list on each coordinate in the global_array
           ˜      # Flatten the entire list
            2£    # Only leave the first two integers as `x,y`-coordinate
                  # (if 05AB1E could remove inner lists, this would've been `¯Kн` instead)
              DˆU # Replace variable `X` with this, and add it to the global_array
}®                # After the loop: push all coordinates sorted in a spiral from the register
  J               # Join each coordinate together to a string
   ¯J             # Push the global_array, and also join them together to a string
                  # (if 05AB1E could index inner lists, both `J` could have been removed)
     k            # Get the index of each item of the global_array in the spiral list
      >           # Increase the 0-indexed index by 1 to make it 1-based
       θ          # And only leave the last one (which is output implicitly)

The sorting part Σ·nàDtyÆ+yO·<.±*->} is copied from my other answer. This can most likely be golfed though, since we don't need the values of the spiral, but only need to sort the \$x,y\$-coordinates.

MATL, 41 37 bytes
62lYLt1=i:"YYw(t5Mf'<@{}'ot_h+)X<y=])

Input is 0-based.
Try it online!

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Classic VCS ASCII Adventure
Growing up, my first console game system was an Atari 2600 and I will always have a love for some of those games I so enjoyed as a child.  Many of the graphics are still memorable, perhaps even iconic.
It turns out that these sprites are very simplistic bitmaps, 8 pixels wide with variable height where the binary representation is the arrangement of the pixels.
For example, the hex bytes 0x18, 0x24, 0x18 would draw a crude circle like so:
0x18: 00011000
0x24: 00100100
0x18: 00011000

As 8 pixels wide creates fairly small graphics (even by Atari 2600 standards) it was common to double or quadruple either the height, width or both to create a larger (though more blocky and distorted) version of the same image.  They would commonly also be flipped vertically or horizontal for both player sprites and playfields. The game Combat is a good example of this.
The challenge is, to write code to display these sprites as "graphics" in ASCII form including the ability to stretch or flip them vertically, horizontally or both. This must be in the form of either a full program, or callable function.
Input:

An array of bytes, each representing the horizontal bits for that line.
A non-zero integer value for each direction, horizontal and vertical representing the scaling factor for that dimension.
A negative value indicates that the dimension should also be flipped along it's axis.

Output:

ASCII representation to STDOUT or a newline-separated string, using a space character for black (0) pixels and any printable, non-space character of your choice for white (1) pixels.

Test data:
bmp1 = [ 0x06, 0x0F, 0xF3, 0xFE, 0x0E, 0x04, 0x04, 0x1E, 0x3F, 0x7F, 0xE3, 0xC3, 0xC3, 0xC7, 0xFF, 0x3C, 0x08, 0x8F, 0xE1, 0x3F ]
bmp2 = [ 0x07, 0xFD, 0xA7 ]
bmp3 = [ 0x00, 0x8E, 0x84, 0xFF, 0xFF, 0x04, 0x0E, 0x00 ]
bmp4 = [ 0x00, 0xFC, 0xFC, 0x38, 0x3F, 0x38, 0xFC, 0xFC]

Note: Above example input arrays of bytes are provided as hex.  If your platform does not accept hex literals for byte representation you may convert them to a native byte-equivalent literal.
Example Output:
f( bmp1, 1, 1 ) =>
--------
     XX
    XXXX
XXXX  XX
XXXXXXX
    XXX
     X
     X
   XXXX
  XXXXXX
 XXXXXXX
XXX   XX
XX    XX
XX    XX
XX   XXX
XXXXXXXX
  XXXX
    X
X   XXXX
XXX    X
  XXXXXX
--------

f( bmp1, -2, 1 ) =>
----------------
  XXXX
XXXXXXXX
XXXX    XXXXXXXX
  XXXXXXXXXXXXXX
  XXXXXX
    XX
    XX
  XXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXXXX
XXXX      XXXXXX
XXXX        XXXX
XXXX        XXXX
XXXXXX      XXXX
XXXXXXXXXXXXXXXX
    XXXXXXXX
      XX
XXXXXXXX      XX
XX        XXXXXX
XXXXXXXXXXXX
----------------

f( bmp2, 1, 2 ) =>
--------
     XXX
     XXX
XXXXXX X
XXXXXX X
X X  XXX
X X  XXX
--------

f( bmp2, 2, 1 ) =>
----------------
          XXXXXX
XXXXXXXXXXXX  XX
XX  XX    XXXXXX
----------------

f( bmp2, -2, -2 ) =>
----------------
XXXXXX    XX  XX
XXXXXX    XX  XX
XX  XXXXXXXXXXXX
XX  XXXXXXXXXXXX
XXXXXX
XXXXXX
----------------

f( bmp3, 1, -1 ) =>
--------

    XXX
     X
XXXXXXXX
XXXXXXXX
X    X
X   XXX

--------

f( bmp3, 3, 3 ) =>
------------------------

XXX         XXXXXXXXX
XXX         XXXXXXXXX
XXX         XXXXXXXXX
XXX            XXX
XXX            XXX
XXX            XXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
               XXX
               XXX
               XXX
            XXXXXXXXX
            XXXXXXXXX
            XXXXXXXXX

------------------------

f( bmp4, -1, -1 ) =>
--------
  XXXXXX
  XXXXXX
   XXX
XXXXXX
   XXX
  XXXXXX
  XXXXXX

--------

f( bmp4, 4, 2 ) =>
--------------------------------

XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
        XXXXXXXXXXXX
        XXXXXXXXXXXX
        XXXXXXXXXXXXXXXXXXXXXXXX
        XXXXXXXXXXXXXXXXXXXXXXXX
        XXXXXXXXXXXX
        XXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
--------------------------------

Note: the horizontal lines above and below are to show the beginning and end of the output.  They are not required in the output, however empty lines (represented by all zeros/spaces) at the beginning and/or end are required, as shown.
Note 2: these test bitmaps were inspired by and re-drawn/coded based on game screenshots tagged as "fair use" on Wikipedia.
Winning Criteria

This is code-golf, so the shortest code in bytes per language wins.
Standard loopholes are forbidden.

"Somebody get this freakin' duck away from me!" - Strong Bad

The irony is that even the cleverest golfing here will probably not be as clever as what programmers for the Atari 2600 actually had to do if they wanted anything more interesting than a Pong clone -- the whole screen was rendered one line at a time and the CPU spent most of its time doing that. With only 128 bytes of RAM, there was no room for a luxury like a screen buffer... The five whole sprites you got were the luxury.

Can we take the input as a list of 8-bit binary-strings, or similar formats where the bytes are already unpacked into bits?

@LuisMendo "If your platform does not accept hex literals for byte representation you may convert them to a native byte-equivalent literal."

@KevinCruijssen That's the point, I don't know what is accepted as equivalent. Does that open the door to inputting the bitmap directly?

@LuisMendo Good point. And that does lead me to a follow-up/related question: if my language default binary format are strings of 0s and 1s, are we also allowed to take the 0s and 1s as a list of characters? Usually a string input and character-list input are both allowed by default, but I wonder if that's also the case if the language doesn't see the list of 0s and 1s as a single byte by default in this challenge. (It would save a byte in my answer, though. ;p)

+1 for the first paragraph. I was a ZX Spectrum guy but I hear what you are saying about the nostalgia.

@gwaugh :P would have used more languages but not sure what are good "less common languages" to use - most are too similar to another language (functional languages), or esoteric, or (basically) completely unfit for string manipulation (e.g. Ada)

@ASCII-only yeah, I left it deliberately vague and up to the submitter's interpretation. Lisp (and it's relatives) can be a joy to create specifically formatted output, so I appreciate that one especially. Thx for the entries!

05AB1E, 27 26 bytes
εS²Ä×J³Äи²0‹ií]³0‹iR}˜0ð:»

Takes the input as a list of 8-bit binary-strings, and outputs with 1 as non-space character.
-1 byte thanks to @MagicOctopusUrn.
Try it online or verify all test cases.
Explanation:
ε         # Map the (implicit) input-list to:
 S        #  Convert the binary-String to a list of characters
  ²Ä      #  Take the absolute value of the second input
    ×     #  And repeat each character that many times
     J    #  And then join it back together to a single string again
 ³Ä       #  Take the absolute value of the third input
   и      #  Repeat that string as a list that many times
 ²0‹i     #  If the second input is negative:
     í    #   Reverse each string in the list
]         # Close both the if-statement and (outer) map
³0‹i }    # If the third input is negative:
    R     #  Reverse the list of lists
      ˜   # Flatten the list of lists to a list of strings
0ð:       # Replace all 0s with spaces " "
   »      # And join the strings by newlines (which is output implicitly)

There has to be a 2-byter for 0‹i...

@MagicOctopusUrn There should be a 1-byte for 0‹ indeed.. We do have a 1-byter for >=0, which is d. But we should also have a 1-byter to check for negative imo. Now I just use 0‹ or d_.

All I could come up with was: „íR³²‚0‹Ï.V (full code εε²Ä×}J³Äи0ð:}„íR³²‚0‹Ï.V˜») which isn't an improvement, but does get rid of one of those negative checks.

Also, pretty sure εS²Ä×J³Äи²0‹ií]³0‹iR}˜0ð:» saves a byte. If you can take in a 2D array, you can remove the S entirely for 25 bytes.

@MagicOctopusUrn Ah of course, S²Ä× instead of ε²Ä×}. Thanks! Hmm, if we are allowed to take the binary-inputs as a list of 0s and 1s an additional byte could be saved by omitting the S. Will ask OP if this is allowed. I like your „íR³²‚0‹Ï.V in your other comment as well. :)

Python 2, 117 bytes
def f(m,w,h):
 for r in m[::cmp(h,0)]:print(''.join(' X'[1<<i&r>0]*abs(w)for i in range(8)[::cmp(0,w)])+'\n')*abs(h),

Try it online!

Dyalog APL, 46 42 33 bytes
' #'[⍉⊃{⊖⍣(0>⍺)⍉⍵/⍨|⍺}/⎕,⊂⎕⊤⍨8/2]

Try it online!
-9 thanks to ngn!

each -> reduce: {' #'[⊃{⌽⍣(0>⍺)⊢(|⍺)/⍉⍵}/⍺,⊂⍉⍵⊤⍨8/2]} dfn -> program: ' #'[⊃{⌽⍣(0>⍺)⊢(|⍺)/⍉⍵}/⎕,⊂⍉⎕⊤⍨8/2]

shorter: ' #'[⍉⊃{⊖⍣(0>⍺)⍉⍵/⍨|⍺}/⎕,⊂⎕⊤⍨8/2]. btw, the output for the second test seems reversed in your original solution

@ngn thanks! the inputs for the 2nd example should've been reversed to match the 2nd test-case in the question.

MATL, 24 19 bytes
B,!i|1&Y"2M0<?XP]Zc

Inputs are an array of decimal numbers, horizontal scale, vertical scale.
Try it online!
Explanation
B        % Implicit input: array of numbers. Convert to binary. Gives a zero-one
         % matrix, each row containing the binary expansion of a number
,        % Do twice
  !      %   Transpose
  i      %   Input: number
  |      %   Absolute value
  1&Y"   %   Repeat each row that many times
  2M     %   Push the latest input again
  0<     %   Is it negative?
  ?      %   If so:
    XP   %     Flip vertically
  ]      %   End
  Zc     %   Convert each nonzero into '#'. Zeros are displayed as space
         % Implicit end. Implicit display

Prolog (SWI), 252 bytes
N+E+R:-N<1,R=[];N-1+E+S,R=[E|S].
N*E*R:-R=E,E=[];N<0,reverse(E,F),-N*F*R;[H|T]=E,N+H+S,N*T*U,append(S,U,R).
N/E/R:-N<1,R=[];(E<N,D=E,F=32;D=E-N,F=35),N/2/D/C,R=[F|C].
[H|T]^X^Y^R:-128/H/A,X*A*B,Y*[[10|B]]*C,append(C,D),(T=[],R=D;T^X^Y^S,append(D,S,R)).

Try it online!
Explanation
N+E+R:-N<1,R=[];N-1+E+S,R=[E|S].   Make `R` a list containing `E` repeated `N` times
       N<1,R=[]                    If `N<1`, let `R` be the empty list
       N-1+E+S                     Else recurse with `N-1`, `E` and `S`
           R=[E|S]                 Let `R` be a new list with `E` as head and `S` as tail
N*E*R:-R=E,E=[];N<0,reverse(E,F),-N*F*R;[H|T]=E,N+H+S,N*T*U,append(S,U,R).
                                   Let `R` be a list
                                   with each element in `E` repeated `N` times
                                   e.g. 2*[3, 6] -> [3, 3, 6, 6]
       R=E,E=[]                    Let `R` be `E` if `E` is the empty list
       N<0,reverse(E,F)            Else if `N<0`, let `F` be the reverse of `E`
           -N*F*R                  Recurse with `-N`, `F` and `R`
       [H|T]=E                     Else let `H` be the head and `T` be the tail of `E`
           N+H+S                   Let `S` be `N+H+S` (our function, not addition)
           N*T*U                   Recurse with `N`, `T` and `U`
           append(S,U,R)           let `R` be the concatenation of `S` and `U`
N/E/R:-N<1,R=[];(E<N,D=E,F=32;D=E-N,F=35),N/2/D/C,R=[F|C].
                                   Make `R` the binary representation of `E`
                                   with `N` as the value of the current bit
                                   where 0 and 1 are space and hash respectively
    N<1,R=[]                       If `N<1` let `R` be the empty list
    (
        E<N,D=E,F=32               If `E<N` the bit isn't set, so `D=E`, `F=space`
        D=E-N,F=35                 Else `D=E-N`, `F=hash`
    )
        N/2/D/C                    Recurse with `N/2`, `D` and `C`
        R=[F|C]                    Let `R` be a new list with `F` as head and `C` as tail
[H|T]^X^Y^R:-128/H/A,X*A*B,Y*[[10|B]]*C,append(C,D),(T=[],R=D;T^X^Y^S,append(D,S,R)).
                                   Make `R` the result,
                                   with inputs being the list `[H|T]`
                                   and the scales `X` and `Y`
   128/H/A                         Let `A` be the binary representation of `H` (8 bits)
   X*A*B                           Let `B` be `A` with each element repeated `X` times
   Y*[[10|B]]*C                    Let `C` be `B` with a newline prepended,
                                   repeated `Y` times
   append(C,D)                     Let `D` be `C` flattened by one level (joining lines)
   (
       T=[],R=D                    If `T` is empty, let `R` be `D`
       T^X^Y^S                     Else recurse with `T`, `X`, `Y` and `S`
           append(D,S,R)           Let `R` be the concatenation of `D` and `S`
   )

Charcoal, 28 bytes
ＦθＥ↔ζ⭆⮌↨ι²×§ Xμ↔ηＦ›η⁰‖Ｆ‹ζ⁰‖↓

Try it online! Link is to verbose version of code. Explanation:
Ｆθ

Loop over the list of bytes.
Ｅ↔ζ

Map over the vertical scaling factor, thus multiplying the output lines.
⭆⮌↨ι²×§ Xμ↔η

Convert the input to base 2, reverse it, map the digits to space and X, then multiply each character by the horizontal scaling factor.
Ｆ›η⁰‖

If the horizontal scaling factor was positive, reflect to get the image the correct way around again.
Ｆ‹ζ⁰‖↓

Reflect vertically if the vertical scaling factor was negative.

Not that it would save any bytes, but I'm just curious: why did you use F (For) instead of ¿ (If) for the checks?

@KevinCruijssen In Charcoal succinct mode the else is implied so the only time I can use if is if it's the last statement in the block.

Ah ok, didn't knew about that. So using two If here would actually be an If ... Else If ... instead of two loose If. Hmm, good to know.

C (clang), 120 bytes
k,w,l,_;f(*o,z,x,y){for(w=z*y;w;)for(k=w>0?z*y-w--:++w,_=l=8*x;_;putchar(_?o[k/y]>>(l>0?--l/x:7-++l/x)&1?88:46:10))_=l;}

Try it online!

Saved 2 bytes thanks to ceilingcat

Common Lisp, 157 bytes
(lambda(l x y)(dolist(i(if(< y 0)(reverse l)l))(dotimes(j(abs y))(dotimes(n 8)(dotimes(k(abs x))(princ(if(logbitp(if(< x 0)n(- 7 n))i)"#"" "))))(princ"
"))))

Try it online!
Explanation
(lambda(l x y)                           ; Lambda with parameters `l`, `x`, `y`
    (dolist
        (i                               ; For `i` in the list
            (if(< y 0)(reverse l)l)      ; The reverse of `l` if `y<0` else `l`
        )
        (dotimes(j(abs y))(dotimes(n 8)(dotimes(k(abs x))
                                         ; Do `y` times, for `n` from 0 to 7, do `x` times
        (princ(if(logbitp(if(< x 0)n(- 7 n))i)"#"" "))))
                                         ; If `x<0` and the `n`th bit is 1
                                         ; or `x>0` and the `7-n`th bit is 1
                                         ; print "#", else print " "
        (princ"
")                                       ; After every `y` loop, print a newline
        )
    )
)

Tcl, 192 bytes
proc f {l x y} {lmap i [if $y<0 {lreverse $l} {lindex $l}] {time {lmap n {0 1 2 3 4 5 6 7} {time {puts -nonewline [expr $i&1<<($x<0?$n:7-$n)?{#}:{ }]} [expr abs($x)]};puts {}} [expr abs($y)]}}

Try it online!
proc f {l x y}                           Define a function `f` with arguments `l`, `x`, `y`
{lmap i                                  For each `i` in
    [if $y<0 {lreverse $l} {lindex $l}]  The reverse of `l` if `y<0` else `l`
    {
        time {                           Do `abs(y)` times
            lmap n {0 1 2 3 4 5 6 7} {   For `n` from 0 to 7
                time {                   Do `abs(x)` times
                    puts -nonewline      Print without newline
                         [expr $i&1<<($x<0?$n:7-$n)?{#}:{ }]
                                         If `x<0` and the `n`th bit is 1 or
                                         `x>0` and the `7-n`th bit is 1
                                         then return "#" else return " "
                } [expr abs($x)]
            };
            puts {}                      Print a newline
        } [expr abs($y)]
    }
}

8088 machine code, IBM PC DOS, 77 71 bytes
Assembled:
B402 84FF 7906 FD03 F14E F6DF 518A CFAC 5051 B108 8AF3 84F6 7902 F6DE
518A CEB2 2384 DB79 04D0 C8EB 02D0 C072 02B2 2050 CD21 58E2 FA59 E2E4
B20D CD21 B20A CD21 5958 E2CC 59E2 C5

Listing:
    PR_BMP  MACRO BMP, SZBMP, ZX, ZY
            LOCAL LOOP_Y, LOOP_Y2, LOOP_X, LOOP_X2, X_POS, X_NEG
B4 02   MOV  AH, 2          ; DOS display char function
84 FF   TEST ZY, ZY         ; is Y scale negative?
79 06   JNS  LOOP_Y         ; if positive, start Y LOOP
FD      STD                 ; direction flag start from end
03 F1   ADD  BMP, CX        ; advance input byte array to end
4E      DEC  BMP            ; zero adjust index
F6 DF   NEG  ZY             ; make counter positive
     LOOP_Y:
51      PUSH CX             ; save outer byte loop counter
8A CF   MOV  CL, ZY         ; set up repeat counter (Y scale factor)
AC      LODSB               ; load byte into AL
     LOOP_Y2:
50      PUSH AX             ; save original AL
51      PUSH CX             ; save outer loop
B1 08   MOV  CL, 8          ; loop 8 bits
8A F3   MOV  DH, ZX         ; DH is positive X scale used as counter
84 F6   TEST ZX, ZX         ; is X scale negative?
79 02   JNS  LOOP_X         ; if so, make counter positive
F6 DE   NEG  DH             ; compliment X counter
    LOOP_X:
51      PUSH CX             ; save bit counter
8A CE   MOV  CL, DH         ; set repeat counter (X scale factor)
B2 23   MOV  DL, '#'        ; by default, display a #
84 DB   TEST ZX, ZX         ; is X scale negative?
79 04   JNS  X_POS          ; if so, rotate left 1 bit
D0 C8   ROR  AL, 1          ; else rotate right LSB into CF
EB 02   JMP  X_NEG          ; jump to examine CF
    X_POS:
D0 C0   ROL  AL, 1          ; rotate left MSB into CF
    X_NEG:
72 02   JC   LOOP_X2        ; is a 1?
B2 20   MOV  DL, ' '        ; if not, display a space
    LOOP_X2:
50      PUSH AX             ; save AL (since silly DOS overwrites it)
CD 21   INT  21H            ; display char
58      POP  AX             ; restore AL
E2 FA   LOOP LOOP_X2        ; loop repeat counter
59      POP  CX             ; restore bit counter
E2 E4   LOOP LOOP_X         ; loop bit counter
B2 0D   MOV  DL, 0DH        ; display CRLF
CD 21   INT  21H
B2 0A   MOV  DL, 0AH
CD 21   INT  21H
59      POP  CX             ; restore outer loop
58      POP  AX             ; restore original AL
E2 CC   LOOP LOOP_Y2        ; loop row display
59      POP  CX             ; restore byte counter
E2 C5   LOOP LOOP_Y         ; loop byte counter
    ENDM

This turned out to be more of a doozy in ASM than I originally thought.  Multiple concurrent loops and lots of if/else branching can certainly give you headaches.
This is implemented as a MACRO since it allows function-like parameter passing for testing.
Output
Here is a test program for DOS that prompts for the X and Y scaling factor and draws to the screen.  Note, scaling the dragon too much will scroll past the top since default DOS window is only 24 rows.

And here's our little dragon (duck):

Try it Online!
You can test in a DOS VM using DOSBox or VirtualConsoles.com with the following steps:

Download VCS.ZIP (contains all four executables)
Go to https://virtualconsoles.com/online-emulators/DOS/
Upload the ZIP file you just downloaded, click Start
Type PLANE, KEY, TANK or DRAGON.

PowerShell, 146 132 bytes
param($x,$y,$b)&($t={$b|%({$r+=,$_*$y},{$r=,$_*-$y+$r})[$y-lt0]
$r-ne$e})|%{$b=,$_*8|%{''+' X'[($_-shr$i++%8)%2]}
$y=-$x;-join(&$t)}

Try it online!
Unrolled:
param($x,$y,$bitmap)

$transform={
    $bitmap|%({$r+=,$_*$y},{$r=,$_*-$y+$r})[$y-lt0]
    $r -ne $empty
}

&$transform|%{                                  # $bitmap is an array of lines
    $bitmap=,$_*8|%{''+' X'[($_-shr$i++%8)%2]}  # $bitmap is an array of line pixels now
    $y=-$x                                      # reuse $y
    -join(&$transform)
}

Perl 5, 105 bytes
($_,$h,$v)=@F;say for map{$_=reverse if$h<0;y/0/ /;s/./$&x abs$h/eg;($_)x abs$v}$v<0?reverse/\d+/g:/\d+/g

TIO
If input must be hex
126 bytes

Jelly, 21 bytes
⁴²+BḊ€⁸m€Ṡ}¥xA}ZʋƒYo⁶

Try it online!
Assumes there is at most one command-line argument.

APL (Dyalog Extended), 23 bytesSBCS
dzaima's method
Anonymous tacit prefix function. Takes \$(v,h,B)\$ as argument, where \$v\$ is the vertical scaling factor, \$h\$ is the horizontal scaling factor, and \$B\$ is the byte array as an 8-column packed bit-Boolean matrix (this is the normal and most compact way to represent raw bytes in APL). Requires ⎕IO←0 (zero based indexing).
' x'⊇⍨∘⊃{⊖⍣(>⍺)⍉⍵/⍨|⍺}/

Try it online!
{…}/ reduce right-to-left using the following anonymous lambda:
 |⍺ the magnitude of the left argument (the scaling factor)
 ⍵/⍨ use that to replicate the right argument horizontally
 ⍉ transpose
 ⊖⍣(…) flip if:
  >⍺ the scaling factor is less than zero
⊃ disclose (since reduction enclosed to reduce tensor rank from 1 to 0)
' x'⊇⍨ select elements from the string " x" using that matrix

T-SQL, 216 bytes
Before executing this MS-SQL Studio Management, press CRTL-t to show data as text. The height cannot be adjusted to exceed the number of elements in the input.
Because of the horrible implementation of STRING_AGG, the height variable will only work in MSSM. MS should have made a third optional parameter to include the order of the elements being concatenated.
The online version can only support adjustment of the width. Height will result in a funky result with multiple stacking shapes.
USE master
DECLARE @ table(v int,i int identity)
INSERT @ values
(0x06),(0x0F),(0xF3),(0xFE),(0x0E),(0x04),
(0x04),(0x1E),(0x3F),(0x7F),(0xE3),(0xC3),
(0xC3),(0xC7),(0xFF),(0x3C),(0x08),(0x8F),
(0xE1),(0x3F)
-- @  = width
-- @h = height
DECLARE @s INT=1,@h INT=1

SELECT iif(@s>0,reverse(x),x)FROM(SELECT
string_agg(replicate(iif(v&n=0,' ','X'),abs(@s)),'')x,i,j
FROM(values(1),(2),(4),(8),(16),(32),(64),(128))x(n)
,@,(SELECT top(abs(@h))i j FROM @)g GROUP BY i,j)f
ORDER BY i*@h

This script will not show the correct shapes in the online version, so I made some minor adjustments to compensate.
Try it online

Ruby, 89 bytes
->b,w,h{y=h>0?-1:0;(b*h.abs).map{y+=1;[*1+8*w..0,*0...8*w].map{|x|' X'[b[y/h][x/w]]}*''}}

Try it online!

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Ambiguous Locations on a Grid
You have a little robot with four distance sensors. It knows the layout of a room, but it has no sense of orientation other than being able to lock onto the grid orientation. You want to be able to find out where the robot is based on the readings, but it can be ambiguous because of the limited sensors.
Challenge Explanation
You will be given a room layout and four clockwise distance readings giving the number of cells between you and a wall. There can be walls in the middle of the room and the edges of the grid are also walls. The robot cannot be placed on top of a wall.
Your objective is to list all of the locations within the room that the robot could be in that would give the given readings. Keep in mind that the robot has no sense of orientation (other than being locked to 90 degree angles on the grid- i.e. the robot will never be oriented diagonally or some other skew angle), so a reading of [1, 2, 3, 4], for example, is the same as reading [3, 4, 1, 2].
Examples
For these examples, cell coordinates will be given as 0-indexed (x, y) pairs from the top-left cell. Readings will be given in clockwise order in a square bracketed list. Layouts will use pound signs for walls and other characters (usually dots) to represent empty cells.
Case 1
. . . .
. . . .
. . # .
. . . .

[1, 0, 2, 3] ==> (1, 0), (3, 1)
[0, 0, 3, 3] ==> (0, 0), (3, 0), (0, 3), (3, 3)
[2, 1, 1, 0] ==> (0, 2), (2, 1)
[1, 1, 2, 2] ==> (1, 1)

Case 2
# a . # a .
a # . . # a
. . # . . #
# . . # . .
a # . . # a
. a # . a #

[0, 0, 1, 1] ==> every position on the grid that is a dot
[1, 0, 0, 0] ==> all of the a's on the grid

Case 3
.

[0, 0, 0, 0] ==> (0, 0)

Case 4
. # #
. . .

[1, 2, 0, 0] ==> (0, 1)
[0, 1, 2, 0] ==> (0, 1)
[0, 0, 1, 0] ==> (0, 0)
[1, 0, 1, 0] ==> (1, 1)
[0, 1, 0, 1] ==> (1, 1)

Case 5
. # . .
. . . .
. . # .
. . . .

[2, 1, 1, 0] ==> (0, 2), (2, 1)
[0, 2, 2, 1] ==> (1, 1)
[1, 0, 2, 2] ==> (1, 1)
[0, 3, 0, 0] ==> (0, 0)
[1, 0, 1, 1] ==> (1, 2)

Other Rules

Input may be in any convenient format. Input is a grid of walls and spaces and a list of four distances in clockwise order.
Output may either be a list of all cells that satisfy the reading or a modified version of the grid showing which cells satisfy the reading. The exact format of the output doesn't matter as long as it is reasonable and consistent. Valid output formats include, but are not limited to:

Printing a line for each cell coordinate as an ordered pair
Printing the grid with ., #, and ! for space, walls, and possible locations, respectively.
Returning a list of ordered pairs
Returning a list of indexes
Returning a list of lists using different values for spaces, walls, and possible locations
Return/print a matrix of 0s and 1s, using 1s to represent cells where the reading would occur. (It is not necessary to include walls)
Once again, this list is not exhaustive, so other representations are valid as long as they are consistent and show every possible valid location in a grid or list. If you are unsure, leave a comment and I will be happy to clarify.

You may assume that a reading corresponds to at least one location on the grid.
You may assume that the input grid is at least 1x1 in size and has at least one empty space.
You may assume that the input grid is no larger than 256 cells in each dimension.
You may assume that the input grid is always a perfect rectangle and not jagged.
There is no penalty or bonus if your program happens to give sane outputs for invalid inputs.
This is code golf, so shortest code wins.

The testcases for Case 5 don't seem quite right. I get (0,2),(2,1), (1,3), (1,3), and nothing.

@TFeld Thanks. Fixed.

@Arnauld Seems reasonable to me. I'll add that to the already non-exhaustive list.

JavaScript (ES6),  130 128 126  125 bytes
Takes input as \$(m)(l)\$ where \$m\$ is a binary matrix describing the room layout (\$0\$ = wall, \$1\$ = empty) and \$l\$ is the list of distances.
Returns another binary matrix where each valid position is marked with \$1\$.
m=>l=>m.map((r,y)=>r.map((v,x)=>v&!!([...'3210321'].map(d=>(g=X=>(m[Y+=~-d%2]||0)[X+=(d-2)%2]?1+g(X):0)(x,Y=y))+g).match(l)))

Try it online! (with post-processed output for readability)
Commented
m => l =>                         // m[] = layout matrix; l[] = list of distances
  m.map((r, y) =>                 // for each row r[] at position y in m[]:
    r.map((v, x) =>               //   for each cell v at position x in r[];
      v &&                        //     yield 0 if v = 0
      !!(                         //     otherwise, test whether we can find l[] within a
        [...'3210321']            //     list containing twice the results of the sensors
        .map(d =>                 //       for each direction d:
          (g = X => (             //         g = recursive function taking X
              m[Y += ~-d % 2]     //         add dy[d] to Y
              || 0                //         use a dummy object if we're out of the board
            )[X += (d - 2) % 2] ? //         add dx[d] to X; if (m[Y] || 0)[X] is equal to 1:
              1 +                 //           add 1 to the final result
              g(X)                //           and do a recursive call
            :                     //         else:
              0                   //           yield 0 and stop recursion
          )(x, Y = y)             //         initial call to g with X = x and Y = y
        )                         //       end of map() over directions
        + g                       //       coerce the result to a comma-separated string,
                                  //       followed by harmless garbage
      ).match(l)                  //     test whether l[] can be found in this string
                                  //     (l[] is implicitly coerced to a string as well)
    )                             //   end of map() over r[]
  )                               // end of map() over m[]

Python 2, 234 202 200 191 bytes
lambda m,a:[(i,j)for j,l in e(m)for i,c in e(l)if('#'<c)*[(''.join(L)[::-1]+'#').find('#')for L in l[:i],zip(*m)[i][:j],l[:i:-1],zip(*m)[i][:j:-1]]in[a[q:]+a[:q]for q in 0,1,2,3]]
e=enumerate

Try it online!

Charcoal, 42 bytes
ＰθＦθ¿⁼¶ι⸿¿№Ｅ⁴Ｅ⁴⊖⌕⁺⪫ＫＤ⊕⌈η✳§⟦→↓←↑⟧⁺κμω#¦#η!ι

Try it online! Link is to verbose version of code. Charcoal seems to add some padding to the output for some reason; I'm assuming it's a bug in Charcoal. Explanation:
Ｐθ

Print the map without moving the cursor.
Ｆθ

Loop over each character in the map.
¿⁼¶ι⸿

If it's a newline then move the cursor to the start of the next line.
⊖⌕⁺⪫ＫＤ⊕⌈η✳§⟦→↓←↑⟧⁺κμω#¦#

Find the distance to the wall in direction k+m.
¿№Ｅ⁴Ｅ⁴...η!ι

Loop over all four starting directions k, peek in all four clockwise directions m, and if the result includes the second input then print a ! otherwise print the current character.

The newer version of Charcoal on ATO doesn't have the padding bug. Additionally, I was able to golf the code down to 36 bytes, so I'll present that version here: Attempt This Online! Link is to verbose version of code.

J, 61 bytes
Takes in the grid with infinity _ for empty tiles, 1 for walls. Returns the grid with either 0 or 1, with the latter indicating a possible position.
e."1 2]]0 1|:i.@4|."{_2+((,-)|.=i.2)([:<./(1+|.!.1)^:(<_))"$]

Try it online!
Can probably further be golfed by trying other arrangements of the different axes.

((,-)|.=i.2) 4 directions in clockwise order: 0 1, 1 0, 0 _1, _1 0
(…)^:(<_)"$ for each direction and the grid
^:(<_) until the output does not change, return all intermediate steps:
1+|.!.1 shift the grid, pushing new 1 in at the borders, incrementing each cell.
[:<./ take the minimum of each cell over all steps.
_2+ Minus 2. We now have the 4 grids, representing each direction, with the cell representing the distance.
i.@4|."{ get all possible rotations of the 4 grids.
0 1|: transpose so that each cell has 4 lists: the possible arrangements of the sensors.
e."1 2]] set cells to 1 if the given sensor input is in the 4 lists, otherwise to 0.