[Question]
  [
There are [clever ways](/q/17456) of determining whether a number is a power of 2. That's no longer an interesting problem, so let's determine whether a given integer is an integer power of **-2**. For example:
```
-2 => yes: (-2)¹
-1 => no
0 => no
1 => yes: (-2)⁰
2 => no
3 => no
4 => yes: (-2)²
```
## Rules
* You may write a [program or a function](//codegolf.meta.stackexchange.com/q/2419) and use any of the [standard methods](//codegolf.meta.stackexchange.com/q/2447) of receiving input and providing output.
* Your input is a single integer, and output must be a truthy value if the integer is an integer power of -2, and a falsy value otherwise. No other output (e.g. warning messages) is permitted.
* The usual integer overflow rules apply: your solution must be able to work for arbitrarily large integers in a hypothetical (or perhaps real) version of your language in which all integers are unbounded by default, but if your program fails in practice due to the implementation not supporting integers that large, that doesn't invalidate the solution.
* You may use any [programming language](//codegolf.meta.stackexchange.com/q/2028), but note that these [loopholes](//codegolf.meta.stackexchange.com/q/1061/) are forbidden by default.
## Winning condition
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") contest: the answer which has the fewest bytes (in your chosen encoding) is the winner.
  
[Answer]
## Mathematica, 22 bytes
```
EvenQ@Log2@Max[#,-2#]&
```
[Try it online!](https://tio.run/nexus/mathics#C07NSU0uiQ5KzEtPjdY1NDDQAeJYnf@uZal5gQ4@@elGDr6JFdHKOrpGyrFq/2MV9PUVAooy80r@AwA "Mathics – TIO Nexus") (Using Mathics instead, where this solution also works.)
I tried to find a solution with bitwise operators for a while, and while one definitely exists, I ended up finding something which is probably simpler:
* `Max[#,-2#]` multiplies the input by **-2** if it's negative. Multiplying by another factor of **-2** doesn't change whether the value is a power of **-2** or not. But now all odd powers of **-2** have been turned into even powers of **-2**.
* But even powers of **-2** are also even powers of **2**, so we can use a simple `Log2@...` and check if the result is an integer (to check whether it's a power of **2**). This already saves two bytes over `Log[4,...]` (another way to look at even powers of **-2**).
* As an added bonus, checking whether a value is an even integer is shorter than just checking whether it's an integer: we can save three more bytes by using `EvenQ` instead of `IntegerQ`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
æḟ-2=
```
[Try it online!](https://tio.run/nexus/jelly#ARkA5v//w6bhuJ8tMj3/LTlyOcK1xbzDh@KCrEf/ "Jelly – TIO Nexus")
### How it works
```
æḟ-2=  Main link. Argument: n
æḟ-2   Round n towards 0 to the nearest power of -2.
    =  Test if the result is equal to n.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
b-2S⁼1
```
[Try it online!](https://tio.run/nexus/jelly#@5@kaxT8qHGP4f///3WNAA "Jelly – TIO Nexus")
This is based on how Jelly converts an integer *N* to any arbitrary base *B*, doing so by converting *N* to an array, in which each integer is a digit *d* of (*N*)*B*, which can have a value 0≤*Vd*<*B*. Here, we will 0-index digits from the right, so every digit adds *VdBd* to form *N*. *Vd*<*B*⇔*VdBd*<*BBd*=*B**d*+1, therefore every possible *N* has only one unique representation, if we ignore leading 0s in (*N*)*B*.
Here, *d*=input, *B*=-2. *N*=*Bd*=1*Bd*=*VdBd*⇔1=*Vd*⇔*Vd*=1, and, since we're not adding any other multiples of powers of *B*, every other *V* would be 0. Right now, the array should be a 1 concatenated with *d* 0s. Since Jelly 1-indexes from the left, we should check whether the array's 1st element is 1, and all other elements are 0.
Hmm... all good, right? No? What's going on? Oh yeah, I have a better idea! First, let's take the sum of all of the integers in the array, treating it as if it was an integer array and not a number in base -2. If it is 1, it means that there is only one 1, and all other integers are 0. Since there can't be leading zeroes, except in the case of 0-2 (where the sum would be 0≠1 anyways), the 1st integer must be non-zero. The only non-zero integer in the array is the 1, so it must be the first one. Therefore, this is the only case that the sum of all of the integers in the array would be 1, because the smallest possible sum of a pair of positive integers is Σ{1,1}=2, since the smallest positive integer is 1. Every integer in a base representation is non-negative, so the only way the sum is 1 is to only have one 1, and all other integers are 0. Therefore, we can just check if the sum of all of the integers in the array is 1.
Here is what the code does:
```
b-2S⁼1 Main link. Arguments: d
b-2    Convert d to base -2.
   S   Take the sum.
    ⁼1 Check if the sum is equal to 1.
```
[Answer]
# [Python](https://docs.python.org/3/), 46 bytes
*-2 bytes thanks to @ovs.*
```
def g(x):
 while x%-2==0!=x:x/=-2
 return x==1
```
Function with usage:
```
g(4) # put your number between the brackets
```
[Try it online!](https://tio.run/##K6gsycjPM/r/PyU1TSFdo0LTikuhPCMzJ1WhQlXXyNbWQNG2wqpC31bXiEuhKLWktChPocLW1vB/QVFmXglQg4nmfwA)
[Answer]
# [Python 2](https://docs.python.org/2/), ~~35~~ ~~34~~ 32 bytes
```
f=lambda n:n==1or n!=n%2<f(n/-2)
```
[Try it online!](https://tio.run/nexus/python2#FcvRCkAwAAXQZ77ieli2sjSKkvmXiUlxafj@4fXUid5ubh8nB3a01hwBzCxF1XvJUlcq@p@wEsFxmaU2TWFa1aXJGVbeyEX9QA8QVw4ByQJfVCq@ "Python 2 – TIO Nexus")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
Y(IÄÝm¹å
```
[Try it online!](https://tio.run/nexus/05ab1e#@x@p4Xm45fDc3EM7Dy/9/9/QDAA)
or as a [Test suite](https://tio.run/nexus/05ab1e#qymr/B@pUXm45fDc3MrDS/9XKh3eb6VweL@Szn9dCy5dEy5dIy5dQy4DLkMuIy5jLhMuQzMA)
**Explanation**
```
Y(         # push -2
  IÄÝ      # push range [0 ... abs(input)]
     m     # element-wise power
      ¹å   # check if input is in the resulting list
```
[Answer]
# JavaScript (ES6), 37 28 24 bytes
```
f=x=>!x|x%2?x==1:f(x/-2)
```
Saved 4 bytes thanks to Arnauld.
```
f=x=>!x|x%2?x==1:f(x/-2)
console.log(f(-2));
console.log(f(-1));
console.log(f(0));
console.log(f(1));
console.log(f(2));
console.log(f(3));
console.log(f(4));
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~98~~ 50 bytes
```
lambda x:x*(x&-x==abs(x))*((x<0)^x.bit_length()&1)
```
[Try it online!](https://tio.run/nexus/python2#BcFLDkAwEADQq8yKGUp8dqI3aUgbyiSUVBdz@3rPa5Mve7vNgkxSoRSNaG3dh0JUIcrc0SKt47ReezjSiVT0lP0TgYEDSLTh2LEZBzUOdU8TvJFDAlalSaXyyJR/ "Python 2 – TIO Nexus")
[Answer]
# Excel, ~~40~~ 36 bytes
Saved 4 bytes by CallumDA
Excel can certainly do it but correcting errors adds 11 bytes
```
=IFERROR(-2^IMREAL(IMLOG2(A1)),1)=A1
```
Input is in cell `A1`. Output is `TRUE` or `FALSE`
If it was allowed to return either `FALSE` or `#NUM!` error for false values, it would be only 25 bytes:
```
=-2^IMREAL(IMLOG2(A1))=A1
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~34~~ 29 bytes
```
f(n){n=n%2?n==1:f(n?n/-2:2);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOs82T9XIPs/W1tAKyLfP09c1sjLStK79n5uYmaehyVXNpaBQUJSZV5KmoaSaEpOnpJOmoWuhqWmNTdwEh7gRDnFD7OIG2IVxqMZhuDF2YRxOxOEjQzOQeC3X/695@brJickZqQA "C (gcc) – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~9~~ 8 bytes
```
2_y|:q^m
```
[Try it online!](https://tio.run/nexus/matl#@28UX1ljVRiX@/@/rgUA "MATL – TIO Nexus") Or [verify all test cases](https://tio.run/nexus/matl#S/hvFF9ZY1UYl/vfJeS/rhGXriGXAZchlxGXMZcJAA).
### How it works
Consider input `-8` as an example
```
2_    % Push -2
      % STACK: -2
y     % Implicit input. Duplicate from below
      % STACK: -8, -2, -8
|     % Absolute value
      % STACK: -8, -2, 8
:     % Range
      % STACK: -8, -2, [1 2 3 4 5 6 7 8]
q     % Subtract 1, element-wise
      % STACK: -8, -2, [0 1 2 3 4 5 6 7]
^     % Power, element-wise
      % STACK: -8, [1 -2 4 -8 16 -32 64 -128]
m     % Ismember. Implicit display
      % STACK: 1
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 28 bytes
```
@(n)any((-2).^(0:abs(n))==n)
```
This defines an anonymous function. The approach is similar to that in my MATL answer.
[Try it online!](https://tio.run/nexus/octave#@@@gkaeZmFepoaFrpKkXp2FglZhUDBTStLXN0/yfpmCrkJhXbM2VBpLWUQBShmDKAExC2BAJYzBpovkfAA "Octave – TIO Nexus")
[Answer]
# Regex (ECMAScript / Java), ~~38~~ ~~37~~ ~~34~~ 33 bytes
```
\b(?=(^|x))((x*)\3\3(?=\3$))*x\1$
```
[Try it online!](https://tio.run/##TY89b8IwGIT/CrUQvG/SmARQVWEMUweGdmjHppUMmMStcSzbQMrHb0@ToVKXG@453em@xFH4jVM2JN6qrXT7ynzLn8ZxI0@9V1k81RbgzBejqMnXsOTwea0RAeoI80k@aZ180keM6jzrN9HojDRUb8EpUwBSr9VGwsN9MkVknqfsVCotATR3Umy1MhIQ77g5aI2XgmvqrVYBhpQOkakdgOEF1dIUocTF@HpV/kW8gOJWOC9XJkDxnn4g/gH5H5hFtsxmHcZQuupEVuYotNr2nDCFnPVIrNmucsDUnEum4hi7QVDzdEkSMiMEY1IT6qSVIsCzCCUVaw@q7aN7ETYlOMSLHwxsezZA9y9j9hB8cG2I3W5NMk6nj5R2@gs "JavaScript (SpiderMonkey) – Try It Online") - ECMAScript  
[Try it online!](https://tio.run/##bVNtT9swEP7Or7hFTLXb4iWwT5gIbdMmTRrbBB@bTnISpzE4TmY7NMD47d05zQZIRFHO9@Ln7p67XItbcXRd3uxU07XWwzXqTLVszuG5pfdKv2qzciMH9Bx0fa5VAYUWzsGFUAYeYLI5LzyK21aV0KCHXHmrzAaE3bjVmoKvbbt18HkoZOdVizcPAL4oLaFKjdyORxKxoi0lQ39E@ce@qqSV5aUUpbSQj2EvjeTfzUmtKOVTXrf0fFsHfEJcmmMPovymjCSUvklNrzVVFXFM/u6FdiR6N5/PI0ofXobuEQjxrwI8IIL/j4AA7xAhx7gb7hbpLDOzID1/3NsefwrvpTVg0@mE3TZdSOAoRzbyttVSGLhPK0SUHK4KYQy2rkzXe0ghdDvZyNWd87JhylAOU59jGKuF@y4Hj2WOFANMhGisHTH2QQYjphYn/2oNGt0hirlOK0@iLGP44iTwkgcTo/ur8bgLlnXCOokK0at4TZdgkledTEuz8fXZMZxDiIRTFMkaEYta2NV6mJoatQvha9aIgYwHkTtiYrp8UhJKF8mawwdrxZ1jldKaDMvZMEO4AcHT2dGMjx1XrQ1sYM2piTmYs9QkKBYLpATxiho5bTC1xXSjRsZdN/hLfMJK9jvGtlZ0ZEpWtN3dj@pSmI3EnOYsPo9Pk2e1YWWUBqIqIA2WZkrkP@zHPZ0G1SLrW6u8JGExKL9Pve3DjJ/cHc7BVyR66yJklPLH8ByEzdxlOTlPya8/A6WEDHOanWQnaMlODimdD1lyuAvrtztK4uP3jIXvXw "Java (JDK) – Try It Online") - Java
Takes its input in unary, as an optional `-` sign followed by a string of `x` characters, the count of which represents the absolute value of the number. (As such, it is not bijective unary, as zero can be represented in two ways. The regex works with both.)
Sets a flag for whether a negative sign is present. Operating on the absolute value, repeatedly divides by 4 (requiring that there is no remainder), and then asserts that the remaining number is 1 if there was no negative sign, or 2 if there was.
```
\b                    # Anchor on the border between {start or "-"} and "x"; in the
                      # domain of this problem, it is actually equivalent to
                      # (?<=^(?=x)|-|x$) - so it can anchor on the end instead of the
                      # beginning, but that would result in a non-match.
(?=(^|x))             # \1 = 1 if negative sign is present, 0 if not
(                     # loop the following:
    (x*)\3\3(?=\3$)   # assert tail is divisible by 4; tail = tail / 4
)*                    # iterate as many times as possible (minimum 0)
x                     # tail -= 1
\1                    # tail -= \1
$                     # assert tail==0
```
## Regex (ECMAScript), 36 bytes
```
^(-(x*)(?=\2$))?((x*)\4\4(?=\4$))*x$
```
[Try it online!](https://tio.run/##TY/NbsIwEIRfhVoIdpPGhCiqKozJqQcO5dAeSyu5YBK3xrFsAyk/z54mh0q9rDTzjWY1X@Io/MYpGxJv1Va6fW2@5U/ruJGnwYssnxoLcOaLSdR@QAJNhFDwdTZELKBX63yd907eOVEzbKPJGWmoX4NTpgSkXquNhIf7JEdknqfsVCktATR3Umy1MhIQ77g5aI2XkmvqrVYBxpSOkakdgOEl1dKUocJFdr0qvxIrUNwK5@XSBCjf0nfEPyD/A7OYFtNZjzFUrj6RpTkKrbYDJ0wpZwMSa7arHTA155KpOMb@Iah5WpCEzAjBmDSEOmmlCPAsQkXFpwfV9dG9CJsKHOLFj0a2Gxug3zdl9hB8cF2I3W5tkqX5I6X9/QU "JavaScript (SpiderMonkey) – Try It Online")
This was the original version I posted; I'm keeping it here, as it's sufficiently different, yet close enough in length, to be interesting.
If it sees a negative sign, it strips it and divides the number by 2 (requiring that there is no remainder). It then asserts that the remaining number is a power of 4.
```
^
(
    -                 # eat a leading negative sign
    (x*)(?=\2$)       # assert tail is even; tail = tail / 2
)?                    # do the above optionally
# Assert that tail is a power of 4
(                     # loop the following:
    (x*)\4\4(?=\4$)   # assert tail is divisible by 4; tail = tail / 4
)*                    # iterate as many times as possible (minimum 0)
x$                    # assert tail == 1; if this fails to match, the regex engine will
                      # try backtracking the loops, but that cannot result in a match
```
# Regex (Perl / PCRE / Boost / Python / Ruby / .NET), 32 bytes
```
^(-)?((x*)\3\3(?=\3$))*x(?(1)x)$
```
[Try it online!](https://tio.run/##RU/LasMwEPyVJYhYm/iluL1UVuxAeu2ptyo1TolBoCau5IKKcH/dldNALsvO7OzObH8y@nH6/AFiOHh9@Wg1kIwHKMr97nW3HaG7GEqsyHm55ehBdQGh7406D7CQ5wUfodbC9loNNJKpTKPYfh/tELaaOGExw9PXrKvubB54fCIN8vmcDaatqXW5QV/rN3YQoeYHfrNWN0hUKa7j0K3X6FUHlEZJ5IKkzBFSiFwEDtqjDQwiiF/IiMnQE7tcXvNe44ZfGP@PTxQfx7Fpnl/2TTO90wQrSt0KZSELWglZEMSVoxVl6JBMU8LyzUOazvUP "Perl 5 – Try It Online") - Perl  
[Try it online!](https://tio.run/##XVBNa4NAEL3nVyyysDOJGk16KF3FS1sIlB7a3mK6GLtGwayLGhBCfrudDT11YYf5ePPezNjazklma8t4z1LmrT0WMtvrk@q1bYtSg1iHy0yp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boost  
[Try it online!](https://tio.run/##NY7basMwDEDf8xXC9EHKxcTNnpKafEiTQba5rYdnB9lj6ddndcdehBDnHLTe0y34brdfa@AE8R5rNvVnDH4A1iyE2F@xoRFxK2nqpg5HPXUHonLDERVtdNgf0Fn1jZoHsLotLoHBgfU5JmP6sL4vwGkn4@psQiGloALsBZzx6Oh07MFV2hWQRZ9FXvzVoPUJ3bmdqf7b1EyVokcru2xkNAu/35BrEI0o0Z9aqsQmyuUtoqcnmEnbw8q5QM@DVsP/Y@E7yR@2yWBMnJW9Ue3xRco8fwE "Python 3 – Try It Online") - Python  
[Try it online!](https://tio.run/##PU9La8MwDL7vV2imUCkjIo@dlppQ6K47jN2SNrTUTQ3GDY5Ls8v@emaXrQcJPul7SO56@J4dSPhUvZoGtuoGm/XXmp3aHyvQMqvgdtZGgZG98uMTgD6BadJ8K6VorajCwjQZc1psK1D2GBhhwuNgtMcl85L@NGyU7f0ZaVUEURMMgu6hOV0cWNAW4pD9pdOYZ8QciQ8YeHcvRLvKapGKNyHoRUwisbw/jATyB1wVGfo5Xj5c/XgPiJ/kATttPdj/zNhjdd37x6br5h2mVCNOCbVlW2It23JBlExYY04TLeY5zbPilTn2Xw "Ruby – Try It Online") - Ruby  
[Try it online!](https://tio.run/##RY/RaoQwEEV/RWQgGW2Crn1aCW7pc79ALVg3WwNpIjGLsuK329hS@jJw5t65zB3tLN00SK13cKJ28lMu7fls5EwvZH@nDCtKlwSboiloJZoCEJOFVjTHBWEnl6f41X6NSstrjCU8RFberJNdP1DQkTIRKDPePa7QCdBsGrXyccMbHpfqRqHjvb0bz7SPTocnFdDVWbuFDApG1Mr49mdTgmFa/nF@cJriemQ4/tb5fpATJYwk9DD6KMOULCSpgzSEPi8fUxAQfy8euM5OeckGO/ktPJ2X/xwxY0N9rYyMwGzbtrM8Oz1zfsxv "PowerShell – Try It Online") - .NET
Uses essentially the same algorithm as the 33 byte ECMAScript version, but in a more straightforward way, which never matches strings outside the problem's domain.
```
^
(-)?                  # \1 = negative sign if it is present; unset otherwise
(                     # loop the following:
    (x*)\3\3(?=\3$)   # assert tail is divisible by 4; tail = tail / 4
)*                    # iterate as many times as possible (minimum 0)
x                     # tail = tail - 1
(?(1)x)               # if \1 is set, then tail = tail - 1, else do nothing
$                     # assert tail == 0
```
---
# Regex (ECMAScript or better), 26 bytes
```
^((.*)\2\2(?=\2$))*(x|oo)$
```
[Try it online!](https://tio.run/##TY9NTwIxFEX/Ck4IvDdIGSbEGGqHlQsWstClaFLhMfO0dJq2fIjw20dmYeLmbs7NvTmfeq/DyrOLw@B4TX5b2y/6bryydOg8U/l4dAAnVYzS5h1ApLjMlznM1DLvIqZwPNc1dpt0dEIR65fo2ZaAIhheEdzdDieIMqhMHio2BGCUJ702bAkQb5TdGYM/pTIiOMMR@kL0UfIGwKpSGLJlrLDIz2cOC70AVk77QHMboXzN3hD/AP0HthjPxtMWY6x8fUjmdq8Nrzte25KmnWRg5Kb2IPlBkeTBANtD4CKbJcdkmtQJCk@OdIQnHSuhPwLwdUxsdVxV4BF/Qq/nrqYRWrmxdLsYor@W5OXSDPNsci9Em78 "JavaScript (SpiderMonkey) – Try It Online") - ECMAScript  
[Try it online!](https://tio.run/##RU/LasMwEPyVJYhImzh@0UKJLNuB9NpTb1UqnBKDQI1dywUX1f11V3YDvQw7s4@ZbS@duZ/ev4B0HJxp3ioDJOKeiux4eD7kI9RNx4gVMc9yjg507Rm6ttPXHlbyuuIjlEbY1uieURnKkAb282x7v6WCXRIkePmY54p/NfY67olCPp@z3rTqSpOl6ErzkpyEx/jEb9b6RonOxNL21XaLTtfAmG/ncUEHuqcNRRigOluvIYL4gYh0ETpi1@sl7RLWf5Lwv/BE83EclXp8Oio1vTIWblCmMmWFkClB3LDhu2mQTNMuje8ewnDGXw "Perl 5 – Try It Online") - Perl  
[Try it online!](https://tio.run/##bVNtT9swEP7Or7hFTLVLMWm1TwQPbdMmTRrbBB/bTnITpzE4dmY7NMD47d05zQaVakWx78XP3T13vhX34vS2uNuq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4VsUfmn3TAjG5Xq65St4dsBpiD0xIf0hL04t0M8wTGaK3RdcIYgEBy1EmodQHGfmgGo3hIYLu7MgkCCY0vTLICMMG9CYb15gk0lwu/0MMnsV7EFNIMHt6q6ZGPtuBrSYyRBV2E9FRTvsppkaX5MfhtJK1F21SqHmteUc0ig8XWbh0T27iNi4ea7RPI8w06cp09U1k0nRrnskoBc8TY5OstD3isiykowzIPfDeIk0RwlhqdNd0ZlZxD0K6cYdzzYuWVYSMLKRvUa7Y@LbNPn4Lei/qwvRCAf01PhB3LV0s9CWL0n@gw09o@g7mcxC38VfndjfMLe/6VgIa9nqeRWH8PgjM/IvtD0Wpz7ODrSG3JfwG "C++ (gcc) – Try It Online") - Boost  
[Try it online!](https://tio.run/##NY5BTsMwEEX3OcXI6mImTa04sErqcpAmSAFcajTY0diIVuLuoS5iM/r6X@9plms@x/Cw@s8lSoZ0TY245iPFMIBYUUqtz4i6prEbO3yyY7chqvHyEyNt1tt8NP3OTAN421anKMDgQ9HolN986Ctgyzot7DMqrRVV4E/ALiDTvuuBt5YrKGAooMzh3aEPGfnYTtT8JTPR1tDNVVhxOrlZXs8oDaC6qFKGQwuOkwMVFdXzS8JAd6CMvodFionuhTXD/4PxK@tv8dlhylKQdWfa7lHrcn8B "Python 3 – Try It Online") - Python  
[Try it online!](https://tio.run/##PU/BasMwDL3vKzRTqB2IcMxO9bxS6K47jN2SzrTUTQ3GDo5LMxj79cwuWw968KT3nqR4OXzNERS8m95MA3pzhe3mY4PR7I8SrOISrmfrDDjVmzQ@ANgTuLZudkqRzhOZB67liLXYSTD@mBW5g@PgbKJLxCX786Azvk9nyp5FNrU5IPvunlOI4MF6KE1MQVvacIZYhHeadbcsSv0LX5OJrEggrPK4P4wM1A9EWcb2sZw9XNJ4Sy9vNJlH6xP4/4UFS2n9@rbVev6kFCvWiU7QterEgrGKTt8hsMU81w0XT4gFfwE "Ruby – Try It Online") - Ruby  
[Try it online!](https://tio.run/##XVBNa8MwDL33V4hgiNWmaRJ2GHOzXLZBYeyw7VZ3Js2cJpDaJkmh0PW3Z3LZaQYLfTy9J8k1bloXrnHAesghWAUQg@v1QfXadWWlebiK54VSTdmNqrJH13a6l1yikO@rIYwgpF9TUh20B5hRm3HgSr1sXp@VwghSJEoiFrPa9py1eSJYl9cEH/jH59PmDQVeoK0567bD2HfakIfLdJfngTQBEng47alC6SiJlin6fn12nf3WPIjjICK8IILKnszom9cZdW2JgWyyEzOAm7T5i5lZ57c6eYsFkjbw287HcqwazvqI1PwBdEl05jEpwnP4ENowKvcDJZAeXPzELeqqsX5MAbRZKsDHwIy4kuj139k4iumL83iOMpMZL3KZMcQ5P/9Yi2yalllydx/H3v4C "PHP – Try It Online") - PCRE2  
[Try it online!](https://tio.run/##RZDRaoQwFER/RcKFJNoElT6tSLf0uV@gFqy9uwbSRJIsytp8u9WW0pcLM5w7MDPZGZ0fUesNXN04vOLSnU4GZ3am2xtjMuVt2ZbsqW5L4Dxly5e1HDZ6fiAv9nNSGj8Ir@Be59XFOuyHkYFOlElAmekW@Ap9DVr4SatAWtlKUqkLg14O9maC0CEpDyaroW/yLu4ZDEzdKBO6H6cCIzT@6eLQWcbXI8PJ1z4MI3pGgB2GEdeQ85UuNKL2uFJLIydps2Pj3ur53e8M57/fd77OTgUUo/Uh7gWK6l8nwth9BK0MJmBijJso8vJRyuN@Aw "PowerShell – Try It Online") - .NET
Takes its input in bijective signed unary. A nonnegative number is a string of `x` characters, and a nonpositive number is a string of `o` characters. The the length of the string is the absolute value of the number.
```
^                     # tail = N = input number
(                     # Loop the following:
    (.*)\2\2(?=\2$)   # Assert tail is divisible by 4; tail = tail / 4;
                      # use "." so that either "x" or "o" can be matched, as
                      # long as all characters are identical.
)*                    # Iterate as many times as possible (minimum 0).
(x|oo)$               # Assert tail == 1 or tail == -2
```
[Answer]
**HP 28s 36 bytes**
```
WHILE DUP ABS 1 > REPEAT 2 NEG / END 1 ==
```
[Answer]
# PHP, 41 Bytes
```
for(;$argn%-2==0;)$argn/=-2;echo$argn==1;
```
# PHP, 52 Bytes
```
echo($l=log(abs($argn),2))==($i=$l^0)&&$argn>0^$i%2;
```
# PHP, 64 Bytes
Working with a Regex
```
echo preg_match("#^".($argn>0?1:"1+0")."(00)*$#",decbin($argn));
```
[Answer]
## JavaScript (ES6), 21 bytes
A recursive function that returns `0` or `true`.
```
f=n=>n==1||n&&f(n/-2)
```
### How it works
This doesn't include any explicit test -- like `n` being odd or `abs(n)` being less than one -- to stop the recursion early when the input is *not* an exact power of -2.
We exit only when `n` is exactly equal to either `1` or `0`.
This does work however because any IEEE-754 float will eventually be rounded to `0` when divided by 2 (or -2) enough times, because of [arithmetic underflow](https://en.wikipedia.org/wiki/Arithmetic_underflow).
### Test cases
```
f=n=>n==1||n&&f(n/-2)
console.log(f(-2));
console.log(f(-1));
console.log(f(0));
console.log(f(1));
console.log(f(2));
console.log(f(3));
console.log(f(4));
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 33 bytes
```
f(n){return n%2?n==1:n&&f(n/-2);}
```
[Try it online!](https://tio.run/nexus/c-gcc#@5@mkadZXZRaUlqUp5CnamSfZ2traJWnpgYU19c10rSu/Z@bmJmnoclVzaWgUFCUmVeSpqGkmhKTp6STpqFroalpjU3cBIe4EQ5xQ@ziBtiFcajGYbgxdmEcTsThI0MzkHgt1/@vefm6yYnJGakA "C (gcc) – TIO Nexus")
[Answer]
# [Python](https://docs.python.org/2/), 24 bytes
```
lambda n:n*n&n*n-1<n%3%2
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPKk8rTw2IdQ1t8lSNVY3@FxRl5pUoROcppOUXKeQpZOYpFCXmpadq6BoaGBjogAhNhcw0hTSNPM3Y/wA "Python 2 – Try It Online")
The bit trick `k&k-1==0` checks whether `k` is a power of 2 (or `k==0`). Checking this for `k=n*n` as `n*n&n*n-1==0` tells us whether `abs(n)` is a power of 2. 
To further see if `n` is a power of -2, we need only check that `n%3==1`. This works because mod 3, the value -2 is equal to 1, so its powers are 1. In contrast, their negations are 2 mod 3, and of course 0 gives 0 mod 3. 
We combine the checks `n*n&n*n-1==0` and `n%3==1` into a single expression. The first can be written with `<1` for `==0`, since it's never negative. The `n%3==1` is equivalent to `n%3%2`, giving 0 or 1. So, we can combine them as `n*n&n*n-1<n%3%2`.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~5~~ 4 bytes
*Ties [emanresu A's Vyxal answer](https://codegolf.stackexchange.com/a/256288) for #1.*
```
2(вO
```
[Try it online!](https://tio.run/##yy9OTMpM/f/fSOPCJv///3WNAQ "05AB1E – Try It Online")
```
2(вO  # full program
   O  # push sum of...
  в   # list of base-10 values of base...
 (    # negative...
2     # literal....
  в   # digits of...
      # implicit input
      # implicit output
```
[Answer]
# Python 3, 34 bytes
```
lambda n:n==(-2)**~-n.bit_length()
```
[Answer]
# Java 7, 55 bytes
```
boolean c(int n){return n==0?0>1:n%-2==0?c(n/-2):n==1;}
```
**Explanation:**
```
boolean c(int n){  // Method with integer parameter and boolean return-type
  return n==0 ?    //  If n is zero:
    0>1//false     //   Return false
   : n%-2==0 ?     //  Else-if n mod -2 is zero:
    c(n/-2)        //   Recursive call for the input divided by -2
   :               //  Else:
    n==1;          //   Return if n is one
}                  // End of method
```
**Test code:**
[Try it here.](https://tio.run/nexus/java-openjdk#LY5BCoMwEEX3nuJTKCSIVqUrbdoTdOWydBFTWwJxIiYWinh2G8XF8Abmz5tRRjqH@xQBzkuvFZbGWtNKgmKaPIhPQ@vHgUBCZLfsmpd0TIq1V4xOScHLMMireQH6sTHBsIu@Vr/QSU2s9oOmz@MJyddDwNsOm1xDICmqwIvAOTCO9wRQ/5xvu9SOPu3DujfENGIcShwCwnOcV1t0jtaalz8)
```
class M{
  static boolean c(int n){return n==0?0>1:n%-2==0?c(n/-2):n==1;}
  public static void main(String[] a){
    for(int i = -2; i <= 4; i++){
      System.out.println(i + ": " + c(i));
    }
  }
}
```
**Output:**
```
-2: true
-1: false
0: false
1: true
2: false
3: false
4: true
```
[Answer]
# [Perl 6](https://perl6.org), 21 bytes
```
{$_==(-2)**(.lsb//0)}
```
[Try it](https://tio.run/nexus/perl6#VY1LasMwFEXnWsUjmEpKkPyJm7YxbhfSFGM7CgT8KZZTMMYF7aikX0@9FG3EscAdZHTh3fvOOUkBbxueBihv4CYt9wLCsbWiMCTMo8sl4ZlMbNuh3XgoK8iOhZCE8jx@Je2Kp2WeEBsz/LTbr2z67Lx0FFoEMMGsSshTVkMIhkqsiAZTIeMGFla0q@d6Cy02JgzvwHOZ8LqKC0mw43pr/3Zzd/@AIXwErNXH0A/n4VOrL62@tfrR6lerP616TOF4@Nd1iwB1I/MR88xfI@QWDH/oEXPNpSiRM6d7tZgMyJub9Zz@NeN8AQ "Perl 6 – TIO Nexus")
## Expanded:
```
{  # bare block lambda with implicit parameter ｢$_｣
  $_                  # is the input
  ==                  # equal to
  (-2)**( .lsb // 0 ) # -2 to the power of the least significant bit of the input
}
```
Note that [`0.lsb`](https://docs.perl6.org/routine/lsb) returns [`Nil`](https://docs.perl6.org/type/Nil) which produces a warning when used as a number, so the defined or operator [`//`](https://docs.perl6.org/routine/$SOLIDUS$SOLIDUS) is used.  
(Think of [`//`](https://docs.perl6.org/routine/$SOLIDUS$SOLIDUS) as [`||`](https://docs.perl6.org/routine/$VERTICAL_LINE$VERTICAL_LINE) with a different slant)
A method call with no invocant where a term is expected is implicitly called on [`$_`](https://docs.perl6.org/syntax/$DOLLAR_SIGN_). ([`.lsb`](https://docs.perl6.org/routine/lsb))
[Also works with](https://tio.run/nexus/perl6#VY1dasJAFIXfZxUXCZ0ZJZMfrbaGaReiEmIcQTCJZGIhhBRmR8XW1rxmKbORmIH0wacD95z7fWcp4GPO4gAlJTzF2U4A7yor5JzYPh2PCUvk1nFcWnf7LIfjIRWSUJZEJ1JNWJwlW@JgG7@vdxOHrtxNTaFCAD3MyoU8HwvgYKjECmnQFzIqYWSF62Kol1BhY8LwCUbFijxKJcGu509nz/PFyysG/gZYq6@2aS/tt1Y/Wl21@tXqT6ubVg2mcNj/6@pRgOrO9s1TKeQSDLxtkO2ZS5ohd0jvYdHjkT800yFnj4zLHQ "Perl 6 – TIO Nexus") [`.msb`](https://docs.perl6.org/routine/msb).
[Answer]
# R, 22 bytes
Takes input from stdin, returns `TRUE` or `FALSE` accordingly.
```
scan()%in%(-2)^(0:1e4)
```
I'm not 100% sure that this is a valid answer, as it only works for integers up to R's size limit, and if the integers were unbounded it wouldn't work. However, the rules state:
> 
> The usual integer overflow rules apply: your solution must be able to work for arbitrarily large integers in a hypothetical (or perhaps real) version of your language in which all integers are unbounded by default, but if your program fails in practice due to the implementation not supporting integers that large, that doesn't invalidate the solution.
> 
> 
> 
In a hypothetical version of R which *does* allow unbounded integers, then we could use the following code, for the same byte count:
```
scan()%in%(-2)^(0:Inf)
```
Of course, in real R, the above code just gives `Error in 0:Inf : result would be too long a vector`.
[Answer]
# Haskell, 24 23 bytes
```
f 0=0
f 1=1
f n=f(-n/2)
```
Defines a function `f` which returns `1` for powers of -2 and `0` otherwise.
A golfed version of my first submission to the [other challenge](https://codegolf.stackexchange.com/a/115641/67875).
[Answer]
# [Julia 0.5](http://julialang.org/), 20 bytes
```
!n=n∈(-2).^(0:n^2)
```
[Try it online!](https://tio.run/nexus/julia5#@6@YZ5v3qKNDQ9dIUy9Ow8AqL85I839afpFCnkJmnoKuqaGRFRBzcWamKSjmcXFyOhQUZeaVpGkoqZqkxOQp6SjkaXJxpualcAHxfwA "Julia 0.5 – TIO Nexus")
[Answer]
# Pyth, 7 bytes
```
!tsjQ_2
```
[Test suite](http://pyth.herokuapp.com/?code=%21tsjQ_2&input=-7&test_suite=1&test_suite_input=-2%0A-1%0A0%0A1%0A2%0A3%0A4%0A5%0A6&debug=0)
Explanation:
```
     _2   # -2
   jQ     # Cast input to that base
          # Iff input is a power of -2, then jQ_2 returns something of the form [1]+[0]*n
          # where n is the power of -2
          # This is also the only situation in which the sum of that is 1
!ts       # so we check for that: is the (s)um equal to 1 (or, equivalently, "!(sum - 1)" )
```
[Answer]
# [Risky](https://github.com/Radvylf/risky), 14 bytes
```
__-+_-2{[?+_0:__0+_0+__?+_0
```
[Try it online!](https://radvylf.github.io/risky?p=WyJfXy0rXy0ye1s_K18wOl9fMCtfMCtfXz8rXzAiLCJbLTRdIiwwXQ)
**Explanation:**
* `__-+_-`: `-2`, written as `-1 + -1` with padding
* `2`: Power
* `{[?+_0`: `log_2(abs(input))`, with `+_0` as padding
* `:`: Equals
* `__0+_0+__?+_0`: Input (`?`), with padding
So basically, `-2 ** log_2(abs(input)) == input`
[Answer]
# x86-32 machine code, ~~20 18~~ 16 bytes
-2 bytes thanks to @xiver77
-2 bytes by removing an unnecessary jump
(This submission was originally 19 bytes, but I adjusted it to 20 since I forgot to add `ret`).
```
00000000: f8a9 ffff 7f00 7507 c1f8 1730 e0d1 f8c3  ......u....0....
```
[Try it online!](https://tio.run/##dVJbbsIwEPz3KbauKjkSqSBBKqKAeoZeIDKOA64cG8UGQiuu3nTjkEBf@@FoZ2dfsxG7XbwRorlXRuh9LmGhrPOV5OWKXLG18k76W0RoVSL4DXI@VwZZZG2tBuWM3OzsMWGFttxDHcEHAbQ9ktIk83B6JgHIMu7KLMPvwWrulZbosFfKQrS10h5A8noED5Omx4QWQ9xL5zvCuH4qWhtCb@YdpMnJADheddQkHbDaVsD1CPj2StsGWvAxfx76RjT4c6DLFyEEBXaKeqRCrx48TKXRZb9K@n1lgLWyRLj0mZCDVXmY@qc4QboTLG/kq/s6qO98Luzew2IBdftQiFdAL2FVDOP8YtOTdMgLy2gn/yEZS/9qFRzUQIfR8XpQcmVYP3K3Ae@qH7d4PmB3XQFlHqUtWNRTr6WVgdWqT@pPyHjUAedb3cbYtolnJJ6SOCHxhIzJhCQkJVMy@xSF5hvXxGWa4IP/0RLnk/oL "C++ (gcc) – Try It Online")
Expects a single precision float in `eax`. Output is in the carry flag.
It takes advantage of some fundamental properties of floats, for some power of -2 `n`:
* `abs(n)` is a power of 2, therefore `n`'s mantissa must be 0.
* `n` is positive for odd numbered exponents, and negative for even exponents. In other words, `sign ^ exponent[0] = 1` where `exponent[0]` is the least significant bit of the exponent.
NASM source:
```
[BITS 32]
isnegpow2:
    ; Clear carry
    clc
    ; Check if mantissa is non-zero
    test eax, 0x7fffff
    ; If it is, then abs(eax) is not a
    ; power of 2, so eax cannot be a power
    ; of -2
    jnz .end
    ; Shift away the mantissa
    sar eax, 23
    ; Now ah contains the sign,
    ; and al contains the exponent.
    ; For powers of -2, sign ^ exponent[0] = 1
    xor al, ah
    ; Check lsb by shifting it to the carry flag
    ; If it's 1, then eax is a power of -2, so the
    ; carry will be set
    sar eax, 1
.end:
    ret
```
[Answer]
# Javascript(ES7), 45 bytes
```
x=>-1**Math.log2(Math.abs(x))*Math.abs(x)==x
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org/pldoc/doc/home/jan/src/plweb/index.html), 44 bytes
```
p(X):-X=1;X\=0,X mod 2=:=0,Z is X/(-2),p(Z).
```
[Online interpreter](http://swish.swi-prolog.org/p/naQGHdxk.pl)
]