# Do two numbers contain unique powers of 2

Break two numbers up into their powers of 2, if they share any, return a falsey value. Otherwise, return a truthy value.

If one input is 0, the answer will always be truthy. if one input is 255, the answer will be falsey if the other is not 0.

# Example

Given 5 and 3

5 = 2⁰ + 2²
3 = 2⁰ + 2¹


Both share 2⁰, return falsey.

Given 8 and 17

8  = 2³
17 = 2⁰ + 2⁴


Neither share any powers, return truthy.

# I/O

Input and output can be through any standard means

Input will always be two integers in the range 0 <= n <= 255

Output should be one truthy or falsey value

# Test Cases

Truthy:
1, 2
3, 4
2, 4
8, 17
248, 7

Falsey:
1, 3
6, 4
8, 8


Standard Loopholes apply.

This is , so fewest bytes wins!

• Can I output 0 for truthy and 1 for falsey instead? Jun 5, 2017 at 5:35
• @KritixiLithos Although it often depends on the language as to what counts as Truthy or Falsey, this is usually acceptable. EDIT: Read the comment wrong, backwards output is not acceptable. Jun 5, 2017 at 5:36
• Do all truthy inputs have to result in the same truthy value? Jun 5, 2017 at 6:02
• @Dennis They can be different values, as long as they are Truthy/Falsey Jun 5, 2017 at 6:02
• This challenge is way too trivial. Jun 5, 2017 at 15:52

# Actually, 2 bytes

&Y


Try it online!

Explanation:

&Y
&   bitwise AND
Y  boolean negation


# x86 Machine Code, 5 bytes

20 C8 0F 95 C0


takes inputs in al and cl, and returns output in al, and is equivalent to:

and al, cl
setnz al

• You could make this follow a standard calling convention (specifically, the Windows 64-bit calling convention, or Windows 32-bit __fastcall) by receiving the parameters in cl and dl. The setnz al instruction would remain the same, since a result is always returned in eax (or sub-portions thereof). That doesn't change the code size any at all, but makes the code a bit more real-world and callable from other languages. Jun 5, 2017 at 7:25

# Jelly, 2 bytes

&¬


Try it online!

Explanation:

&¬
&   bitwise AND
¬  logical negation

• I was expecting this to be easy, but I didn't think of &, I was not expecting this to be two bytes easy. Jun 5, 2017 at 5:45

# Ruby, 12 bytes

->a,b{a&b<1}


Try it online!

# Mathematica, 12 bytes

BitAnd@##<1&


Pure function taking two positive integers as argument and returning True or False.

# Python, 18 bytes

lambda a,b:not a&b


Try it online!

• 2 bytes saved using <1 rather than not . Jun 5, 2017 at 5:57

# Bash, 10 bytes

!(($1&$2))


Input is via command-line arguments. Output is via exit code, so 0 is truthy and 1 if falsy.

Try it online!

# 05AB1E, 2 bytes

&_


Try it online!

# R, 28 bytes

f=function(a,b)!bitwAnd(a,b)


# JavaScript (ES6), 12 bytes

a=>b=>!(a&b)


Takes input in the currying format.

let f=

a=>b=>!(a&b)

console.log(f(1)(2));
console.log(f(3)(4));
console.log(f(2)(4));
console.log(f(8)(17));
console.log(f(248)(7));
console.log(f(1)(3));
console.log(f(6)(4));
console.log(f(8)(8));

• 1B saved: a=>b=>a&b<1
– Luke
Jun 5, 2017 at 8:03
• @Luke That outputs 0 for all the testcases. In order to make that work I would have to surround a&b with parentheses. Jun 5, 2017 at 8:04
• Oh, nvm then...
– Luke
Jun 5, 2017 at 17:36

## CJam, 23 4 bytes

q~&!


It turns out my previous solution contained an implementation of what was essentially just bitwise AND (which is silly because it used & anyway).

# CJam, 4 bytes

{&!}


Try it online!

# R, 23 bytes

if allowed - this version can get multiple inputs as a1,a2,a3..... b1,b2,b3.....

!bitwAnd(scan(),scan())


# GolfScript, 3 bytes

~&!


Try it online!

## Pyke, 3 bytes

.&!


Try it here!

.&  -  bitwise_and(input_1, input_2)
! - not ^


# Chip, 80 bytes

 AZ BZ CZ DZ EZ FZ GZ HZ
,[',[',[',[',[',[',[',['*Z~S
--)--)--)--)--)--)--)~aef


Try it online!

Takes input as two consecutive bytes. (In the TIO, the characters 'A' and '$' are used, corresponding to values 65 and 36.) This solution has eight chunks, one per bit, plus an extra chunk at the end. Looking at these chunks: A is bit 0x01 of the input. (The letters A though H correspond to a bit each.) Z holds on to a value for the next cycle while producing the previous value. Hence, A and Z are the current and previous values of bit 0x01. [ is an AND-gate; it simply ANDs its two inputs together. So the full row of such gates is performing a bitwise AND of the two bytes. Finally, ) is an OR-gate. All eight AND results are OR'd together, giving us a True is there is a match, and a False otherwise. We want the inverse of that, so use a NOT-gate (~) before passing it to the output. We output via a, e, and f. The a, which corresponds to bit 0x01 of the output, receives the result of the above computation. The other two bits e and f are unconditionally on, together forming 0x30. Therefore, the output is either 0x30 or 0x31, which are the codes for ASCII characters '0' and '1'. The extra stuff is housekeeping, it prevents output for the first cycle (there is no previous value at this point, so there is no reason to do a comparison). ### Alternate solution, also 80 bytes A~.B~.C~.D~.E~.F~.G~.H~. Z~<Z~<Z~<Z~<Z~<Z~<Z~<Z~<*Z~S a[--[--[--[--[--[--[--'ef  This is very similar in style, but uses a different algorithm. Where above we AND each pair of bits, and use OR to reduce the result to a single value, here we OR the negation of each pair of bits, then use AND to reduce. One thing to note: we use an implicit OR here, instead of a proper gate as above. We could have used implicit OR'ing above as well, but there is no byte-savings there. # Java 13 bytes a->b->(a&b)<1  # Rust, 10 bytes |a,b|a&b<1 Attempt This Online! # Desmos, 878587 80 bytes +2 bytes to correct an error pointed out by @Steffan -7 bytes thanks to @aiden-chow D(n)=mod(floor(n/2^{[0...floor(log_2(n+0^n))]}),2) f(a,b)=\{\total(D(a)D(b))=0\}  Try It On Desmos! f returns 1 when they are "truthy" and otherwise undefined. • nice! for it to paste correctly, {...} needs to be \{...\}, and \log_{2}n can just be log2n. Jul 17, 2022 at 18:25 • @Steffan Yeah I forgot, it should have been \{...\}. For me, log2n doesn't work btw. Jul 18, 2022 at 1:08 • Well it can still be log_2n. Jul 18, 2022 at 2:28 • \{...\} won't paste correctly if the built-in functions don't have backslashes in front of them. In this case, you need to replace total with \total. Jul 20, 2022 at 23:40 • But there are a few golfs you can do: 74 bytes. Namely, I utilized a golfier way to convert to binary which only uses 2^{[0...floor(log_2n)]} once, so both X and W are not needed. Jul 20, 2022 at 23:44 # MATL, 3 bytes Z&~  Try it at MATL Online. Explanation  % Implicitly grab both inputs Z& % Bit-wise AND ~ % Negate the result and implicitly display  # Pari/GP, 18 bytes x->y->!bitand(x,y)  Try it online! # Javascript, 28 (a,b)=>!(256&(-~a|-~b)||a&b)  ## QBIC, 12 bytes ?(: and :)=0  This returns -1 for truthy inputs, and 0otherwise. "Bitwise" is something QBasic isn't very good at, and I haven't built any of this stuff into QBIC either. # D, 13 bytes (x,y)=>!(x&y)  Here, (arg1,...)=>result is the D lambda syntax, and the ! and & are common notations for boolean negation and bitwise AND. You can find the whole program coupled with the tests at tio.run. # Lua, 19 bytes a,b=...print(a&b<1)  Try it online! # C (gcc), 18 bytes Uses exit-code 0 as truthy. f(a,b){exit(a&b);}  Try it online! # Pyth, 6 bytes !.&hQe  Test it online! Explanations !.&hQe hQ Get first input number e Get second (implicit) input number .& Bitwise and ! Negate  # PHP, 25 Bytes print 1 for true and nothing for false <?=!($argv[1]&+$argv[2]);  Try it online! • <?=+!($argv[1]&\$argv[2]); -2 bytes Jun 5, 2017 at 14:32
• @FelipeNardiBatista Yes then the arguments must cast from string to integer.Otherwise 40&4 is false and "40"&"4" is true for example Jun 5, 2017 at 14:34
• what about removing just one of the two? it worked with 40&4 Jun 5, 2017 at 14:36
• @FelipeNardiBatista right that cast both values to integer Thank You Jun 5, 2017 at 14:44

# Wise, 11 bytes

&::^~![&&]|


Due to a bug this does not currently work on tio, however it does work on the desktop version.

Here is a slightly longer version that works for both:

&::^~![?~&:]|


Try it online!

# Explanation

Most of our code goes into a logical not, in fact only the first byte is required if you want to get the opposite answer.

&             #Bitwise and
::^~![?~&:]| #Logical not


# Oracle SQL, 34 bytes

-- Begin test cases
WITH T (x, y, desired) AS (
SELECT   1,  2, 1 FROM DUAL UNION ALL
SELECT   3,  4, 1 FROM DUAL UNION ALL
SELECT   2,  4, 1 FROM DUAL UNION ALL
SELECT   8, 17, 1 FROM DUAL UNION ALL
SELECT 248,  7, 1 FROM DUAL UNION ALL
SELECT   1,  3, 0 FROM DUAL UNION ALL
SELECT   6,  4, 0 FROM DUAL UNION ALL
SELECT   8,  8, 0 FROM DUAL)
-- End test cases
SELECT T.*, -SIGN(BITAND(x, y)) + 1 result FROM T
/
`