[Question]
  [
### Task
> 
> Find all the non-negative integers up to and including a given non-zero positive integer *n*, that are prime and the count of `1's` and `0's` in their binary representation (having no leading zeroes) are prime too.
> 
> 
> 
Here are the first five such primes,
```
17, 19, 37, 41, 79
10001, 10011, 100101, 101001, 1001111
```
### Clarifications and rules
* [Default I/O methods are accepted](http://meta.codegolf.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods?noredirect=1&lq=1).
* The answer can be a program or a function.
* If there are no such primes then output garbage or nothing.
* [Standard loopholes](http://meta.codegolf.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default?noredirect=1&lq=1) are forbidden.
* `2 3 5 7` did not make it to the list because in their binary representation number of occurrences of `0's` and `1's` are not prime. Consider `7`whose binary representation is `111`, here `0` occurs zero times and zero is not prime.
* Built-ins are allowed.
* The shortest code in bytes wins!
### Test cases
```
10
[]
100
[17, 19, 37, 41, 79]
150
[17, 19, 37, 41, 79, 103, 107, 109, 131, 137]
```
```
/* Configuration */
var QUESTION_ID = 107050; // Obtain this from the url
// It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 47650; // This should be the user ID of the challenge author.
/* App */
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) {
  return "http://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}
function commentUrl(index, answers) {
  return "http://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}
function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}
function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
function getAuthorName(a) {
  return a.owner.display_name;
}
function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    else console.log(body);
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });
  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);
    var lang = a.language;
    lang = jQuery('<a>'+lang+'</a>').text();
    
    languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
  });
  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);
  langs.sort(function (a, b) {
    if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
    if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
    return 0;
  });
  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }
}
```
```
body { text-align: left !important}
#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}
#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}
table thead {
  font-weight: bold;
}
table td {
  padding: 5px;
}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="language-list">
  <h2>Shortest Solution by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">
    </tbody>
  </table>
</div>
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">
    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~106~~ ~~102~~ 100 bytes
```
k=m=1;p={0}
exec"p^={m%k*k,0};c=bin(k).count\nif{k,c('1'),c('0')-1}<p:print k\nm*=k*k;k+=1;"*input()
```
[Try it online!](https://tio.run/nexus/python2#@59tm2traF1gW21Qy5VakZqsVBBnW52rmq2VrWNQa51sm5SZp5GtqZecX5pXEpOXmVadrZOsoW6orgmiDNQ1dQ1rbQqsCooy80oUsmPycrVsgVqts7WBhippZeYVlJZoaP7/b2hqAAA "Python 2 – TIO Nexus")
### Background
To identify primes, we use a corollary of [Wilson's theorem](https://en.wikipedia.org/wiki/Wilson%27s_theorem):
![corollary of Wilson's theorem](https://i.stack.imgur.com/ordYr.png)
### How it works
We start by initializing **k** and **m** as **1** and **p** as the set **{0}**. Note that **m = 1 = 0!² = (k - 1)!²**. Immediately afterwards, the following code is executed **n** times, where **n** is the integer read from standard input.
```
p^={m%k*k,0};c=bin(k).count
if{k,c('1'),c('0')-1}<p:print k
m*=k*k;k+=1
```
By the corollary, **m % k** will be **1** if **k** is prime and **0** otherwise. Thus, `{m%k*k,0}` will return the set **{k, 0}** if **k** is prime and the set **{0}** otherwise.
If (and only if) **k** is prime, since **p** cannot contain **k** at this point, the in-place symmetric difference `p^={m%k*k,0}` will add **k** to the set **p**. Also, **p** will contain **0** after the update if and only if it does not contain **0** before, so **0 ∊ p** if and only if **k** is even.
On the same line, we define a function **c** via `c=bin(k).count`, which will count the occurrences of its argument in **k**'s binary representation.
The second line produces the actual output. `{k,c('1'),c('0')-1}` returns the set that consists of **k** itself, the number of set bits in **k**, and the number of unset bits in **k**. Since the output of `bin(k)` begins with **0b**, we have to decrement `c('0')` to account for the leading **0**.
If all of them are prime, they will all belong to **p**, which by now contains all prime numbers up to **k** (and potentially **0**). If **k** is a Mersenne number (i.e., if it has only set bits), `c('0')-1` will yield **0**. Since Mersenne numbers are odd, **p** will *not* contain **0**, so the condition will fail.
After (potentially) printing **k**, we multiply **m** by **k²**. Since **m = (k-1)!²** before the update, **m = k!²** after it. After incrementing **k**, the relation **m = (k-1)!²** holds again and we're ready for the next iteration.
[Answer]
# Mathematica, ~~80~~ ~~68~~ 54 bytes
```
Select[p=PrimeQ;Range@#,p@#&&And@@p/@#~DigitCount~2&]&
```
**Explanation**
```
Select[p=PrimeQ;Range@#,p@#&&And@@p/@#~DigitCount~2&]&
       p=PrimeQ                                        (* Store prime check func. in p *)
Select[                                             ]  (* Select *)
                Range@#                                (* from a list {1..n} *)
                        p@#                            (* numbers that are prime *)
                           &&                          (* And *)
                                     #~DigitCount~2    (* whose digit counts in binary *)
                             And@@p/@                  (* are prime as well *)
```
[Answer]
# JavaScript (ES6), ~~123~~ ~~118~~ ~~115~~ ~~111~~ ~~104~~ 96 bytes
*Saved 4 bytes thanks to @Arnauld*
```
G=n=>n?G(n>>1,++a[n%2]):a.some(n=>(P=x=>n%--x?P(x):x)(n)-1)
F=n=>F(n-1,G(n,a=[0,0,n])||alert(n))
```
A combination of three typical recursive functions. Alerts the sequence in reverse order and terminates on a "too much recursion" error.
### Test snippet
(modified to output to the page)
```
alert = s => O.textContent += s + "\n"
G=n=>n?G(n>>1,++a[n%2]):a.some(n=>(P=x=>n%--x?P(x):x)(n)-1)
F=n=>F(n-1,G(n,a=[0,0,n])||alert(n))
F(1000)
```
```
<pre id=O></pre>
```
The main function can return an array for 104 bytes:
```
G=n=>n?G(n>>1,++a[n%2]):a.some(n=>(P=x=>n%--x?P(x):x)(n)-1)
F=n=>n?F(n-1).concat(G(n,a=[0,0,n])?[]:n):[]
```
It can also be non-recursive at the cost of another byte:
```
G=n=>n?G(n>>1,++a[n%2]):a.some(n=>(P=x=>n%--x?P(x):x)(n)-1)
n=>[for(_ of Array(n))if(!G(--n,a=[0,0,n]))n]
```
---
Here's the one I started with: *(Saved 6 bytes thanks to @Arnauld)*
```
P=(n,x=n)=>n>1&--x<2||n%x&&P(n,x)
G=n=>n?G(n>>1,o+=n%2,t++):P(o)&P(t-o)
F=n=>n?F(n-1).concat(P(n)&G(n,o=t=0)?n:[]):[]
```
I tried golfing this further and managed to do it in 104 bytes—then realized I had already found that solution (it's at the bottom of the answer). Don't you hate it when that happens? :P
A non-recursive attempt at the main function (again, same byte count):
```
n=>[for(i of Array(n))if(P(--n)&G(n,o=t=0))n]
```
---
This one takes the easy route of counting how many 0's and 1's are in the binary representation:
```
F=n=>n?F(n-1).concat([n,(G=x=>n.toString(2).split(x).length-1)(0),G(1)].some(n=>(P=x=>n%--x?P(x):x)(n)-1)?[]:n):[]
```
Same thing with an array comprehension:
```
n=>[for(_ of Array(n))if(![--n,(G=x=>n.toString(2).split(x).length-1)(0),G(1)].some(n=>(P=x=>n%--x?P(x):x)(n)-1))n]
```
This one takes a slightly harder route to do the same thing:
```
F=n=>n?F(n-1).concat([n,(G=(x,w=n)=>w&&G(x,w>>1)+(w%2==x))(0),G(1)].some(n=>(P=x=>n%--x?P(x):x)(n)-1)?[]:n):[]
```
And this one takes yet another related route that's as short as the original:
```
F=n=>n?F(n-1).concat([n,o=(G=x=>x&&x%2+G(n>>++t))(n,t=0),t-o].some(n=>(P=x=>n%--x?P(x):x)(n)-1)?[]:n):[]
```
Again, you can golf 8 bytes by making it alert the sequence in reverse order:
```
F=n=>F(n-1,[n,o=(G=x=>x&&x%2+G(n>>++t))(n,t=0),t-o].some(n=>(P=x=>n%--x?P(x):x)(n)-1)||alert(n))
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~17~~ 16 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
BĠL€µ;LÆPẠ
ÆRÇÐf
```
**[Try it online!](https://tio.run/nexus/jelly#ASEA3v//QsSgTOKCrMK1O0zDhlDhuqAKw4ZSw4fDkGb///8xMDA "Jelly – TIO Nexus")**
### How?
```
BĠL€µ;LÆPẠ - Link 1, hasPrimeBits: n  e.g. 7         or 13
B          - convert to binary        e.g. [1,1,1]  or [1,1,0,1]
 Ġ         - group indices            e.g. [1,2,3]  or [3,[1,2,4]]
  L€       - length of €ach           e.g. 3          or [1,3]
    µ      - monadic chain separation
     ;L    - concatenate length       e.g. [3,1]      or [1,3,2]
           -     this caters for the edge case of Mersenne primes (like 7), which have
           -     no zero bits, the length will be 1, which is not prime.
       ÆP  - isPrime?                 e.g. [1,0]      or [0,1,1]
         Ạ - All?                     e.g. 0          or 0
ÆRÇÐf - Main link: N
ÆR    - prime range (primes up to and including N)
   Ðf - filter keep those satisfying
  Ç   - last link (1) as a monad
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 14 bytes
```
ƒNpNbSD_‚OpP&–
```
[Try it online!](https://tio.run/nexus/05ab1e#@39skl@BX1KwS/yjhln@BQFqjxom//9vaGoAAA "05AB1E – TIO Nexus")
**Explanation**
```
ƒ               # for N in [0 ... input]
 Np             # push N is prime
   Nb           # push N converted to binary
     S          # split into individual digits
      D_        # push an inverted copy
        ‚       # pair the 2 binary lists
         O      # sum them
          p     # elementwise check for primality
           P    # product of list
            &   # and with the primality of N
             –  # if true, print N
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~14~~ 13 bytes
```
RBċþd`ÆPPTfÆR
```
[Try it online!](https://tio.run/nexus/jelly#@x/kdKT78L6UhMNtAQEhaYfbgv7//29oagAA "Jelly – TIO Nexus")
### How it works
```
RBċþd`ÆPPTfÆR  Main link. Argument: n
R              Range; yield [1, ..., n].
 B             Binary; convert each integer to base 2.
    d`         Divmod self; yield [n : n, n % n], i.e., [1, 0].
  ċþ           Count table; count the occurrences of 1 and 0 in each binary
               representation, yielding a pair of lists of length n.
      ÆP       Test each count for primality.
        P      Product; multiply the corresponding Booleans.
         T     Truth; get all indices of 1, yielding the list of integers in
               [1, ..., n] that have a prime amount of 0's and 1's.
           ÆR  Prime range; yield all primes in [1, ..., n].
          f    Filter; intersect the lists.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~17~~ 15 bytes
```
LDpÏvybSD_)OpP—
```
Uses the **CP-1252** encoding. [Try it online!](https://tio.run/nexus/05ab1e#@@/jUnC4v6wyKdglXtO/IOBRw5T//w0NDAA "05AB1E – TIO Nexus")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~16~~ 15 bytes
```
:"@tB!t~hshZp?@
```
[Try it online!](https://tio.run/nexus/matl#@2@l5FDipFhSl1GcEVVg7/D/v6GpAQA "MATL – TIO Nexus")
```
:         % Input n (implicit). Push range [1 2 ... n]
"         % For each k in [1 2 ... n]
  @       %   Push k
  tB!     %   Duplicate. Binary expansion as an m×1 vector
  t~      %   Duplicate. Negate
  hs      %   Concatenate horizontally into an m×2 matrix. Sum of each column.
          %   This gives a 1×2 vector. However, for k==1 this gives the sum of
          %   the original 1×2 matrix (m==1). But fortunately it doesn't matter
          %   because 1 is not a prime anyway
  h       %   Concatenate horizontally into a 1×3 row vector
  Zp      %   Isprime function applied on each of those three numbers
  ?       %   If all gave true
    @     %     Push k
          %   End (implicit)
          % End (implicit)
          % Display (implicit)
```
[Answer]
## Perl, 101 bytes
99 bytes of code + `-nl` flags.
```
$r=q/^1?$|^(11+)\1+$/;for$@(2..$_){$_=sprintf"%b",$@;print$@if(1x$@)!~$r&y/01/1/dr!~$r&s/0//gr!~$r}
```
To run it:
```
perl -lne '$r=q/^1?$|^(11+)\1+$/;for$@(2..$_){$_=sprintf"%b",$@;print$@if(1x$@)!~$r&y/01/1/dr!~$r&s/0//gr!~$r}' <<< 150
```
**Some short explanations**  
`$r` holds the classical prime checking regex (`q/^1?$|^(11+)\1+$/`).  
For all numbers between 2 and the input,  
`(1x$@)!~$r` checks if the number is prime,  
`y/01/1/dr!~$r` checks if the number of `0` in the binary representation is prime,  
`s/0//gr!~$r` checks if the number `1` in the binary representation is prime.  
(if the 3 conditions are met, `print$@` prints it).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ÅPʒbTS¢pP
```
Pretty straight-forward.
[Try it online](https://tio.run/##yy9OTMpM/f//cGvAqUlJIcGHFhUE/P9vaGoAAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/w60BpyYlhQQfWlQQ8L9W53@0oYGOoQEQm4Jpg1gA).
**Explanation:**
```
ÅP         # Push a list of all prime numbers below or equal to the (implicit) input
  ʒ        # Filter this list of primes by:
   b       #  Convert it to a binary string
    TS     #  Push 10, and pop and convert it to a list of digits as strings: ["1","0"]
      ¢    #  Count those characters in the binary string
       p   #  Check for both those counts whether they're a prime number
        P  #  Check that this is truthy for both of them
           # (after which the filtered list is output implicitly as result)
```
There seems to be a bug in the count builtin `¢` when using an integer list on a string, so some alternatives to `TS` like `Ð‰`, `0L`, or `1Ý` doesn't seem to work and result in a pair of the binary string instead, unless we add a `§` (cast to string): [Try it online](https://tio.run/##yy9OTMpM/f//cGvAua1JIcGHFtXqHNpmzwXhH57wqGEDqpCBDyrf8PBcbHqWY@hajqkPLPT/v6GpAQA).
[Answer]
# Python, ~~129~~ ~~125~~ 123 bytes
If only zero were prime...
```
p=lambda n:all(n%m for m in range(2,n))*n>1
lambda n:[i for i in range(n+1)if p(i)*all(p(bin(i)[2:].count(x))for x in'01')]
```
[**Try it online**](https://repl.it/FKoP/3)
Function `p` is the prime-checking function, which has `>0` at the end so that it works for zero as well, which would otherwise return `-1`. The anonymous lambda is the lambda that checks all the conditions required.
---
Here's a slightly different method using a set comprehension. The result will be a set. (**124 bytes**):
```
p=lambda n:all(n%m for m in range(2,n))*n>1
lambda n:{i*p(i)*all(p(bin(i)[2:].count(x))for x in'01')for i in range(n+1)}-{0}
```
[Answer]
# [Perl 6](https://perl6.org), 65 bytes
```
{grep {all($^a,|map {+$a.base(2).comb(~$_)},0,1).is-prime},0..$_}
```
[Try it](https://tio.run/nexus/perl6#Ky1OVSgz00u25uLKrVRQS85PSVWw/V@dXpRaoFCdmJOjoRKXqFOTmwjkaask6iUlFqdqGGnqJefnJmnUqcRr1uoY6Bhq6mUW6xYUZeamArl6eirxtf8LSksUwIYZmhr8BwA "Perl 6 – TIO Nexus")
## Expanded:
```
{           # bare block lambda with implicit parameter ｢$_｣
  grep      # find all of the values where
  {         # lambda with placeholder parameter ｢$a｣
    all(    # all junction ( treat multiple values as a single value )
      $^a,  # declare parameter to block
      |\    # slip the following list into the outer list
      # get the count of 0's and 1's in the binary representation
      map
      {             # bare block lambda with implicit parameter ｢$_｣
        +           # turn to numeric ( count the values in the list )
        $a          # the outer parameter
        .base(2)    # in base 2
        .comb(~$_)  # find the characters that are the same as
      },0,1         # 0 or 1
    # ask if $a, count of 0's, count of 1's are all prime
    ).is-prime
  },
  0 .. $_ # Range from 0 to the input inclusive
}
```
[Answer]
# Octave, 73 bytes
```
@(n)(p=primes(n))(all(isprime([s=sum(dec2bin(p)'-48);fix(log2(p))+1-s])))
```
[Try It Online!](https://tio.run/#svX40)
```
@(n)
    (p=primes(n))                           generate prime numbers
        (all(                               from them select those that
            isprime(                        are prime both
                [s=sum(dec2bin(p)'-48);     sum of 1s
                fix(log2(p))+1-s])))        and sum of 0s
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~26~~ 27 bytes
```
ri){mp},{2b_1-,mp\0-,mp&},p
```
Straightforward algorithm, will golf further.
EDIT: Forgot n was inclusive.
[Try it online!](https://tio.run/nexus/cjam#@1@UqVkdn1sQY5QUb6irA2QYgEg1tVqdgv//DQ0MAA "CJam – TIO Nexus")
For fun, this is very similar and also 27 bytes:
```
ri){_mp\2b_1-,mp\0-,mp&&},p
```
**Explanation**
```
ri                          e# Take an int as input
  ){mp},                    e# Take the range up and including to the input, 
                            e#   including only prime numbers
       {                    e# For each prime...
        2b_                 e# Convert it to binary and copy it
           1-,mp            e# Take the top binary number, remove 1's, check if the length 
                            e#   is prime
                \           e# Swap top elements
                 0-,mp      e# Do the same but remove 0's
                      &     e# And
                       },   e# Filter out primes for which the above block was false
                         p  e# Print nicely
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
BċÆPðÐf
ÆRç0ç1
```
[Try it online!](https://tio.run/nexus/jelly#ARwA4///QsSLw4ZQw7DDkGYKw4ZSw6cww6cx////MTUw "Jelly – TIO Nexus")
Unfortunately, I could only tie with @Dennis, but the algorithm seems to be somewhat different so I'm posting this anyway.
## Explanation
Helper function (deletes list elements that don't have a prime number of occurrences of a given bit):
```
BċÆPðÐf
     Ðf   Filter {the first argument}, looking for truthy returns from
    ð     the preceding code, which takes two arguments:
B         Convert {the element being checked} to binary
 ċ        Count the number of occurrences of {the second argument}
  ÆP      Return true if prime, false if not prime
```
Main program:
```
ÆRç0ç1
ÆR        Generate all primes from 2 to the input
  ç0      Call the subroutine to require a prime 0 count
    ç1    Call the subroutine to require a prime 1 count
```
[Answer]
# Haxe, ~~169~~ 171 bytes
```
function f(n,?p)return[for(j in(p=[for(i in 0...++n)i<2?0:i]))if(j>0){var x=j*2,y=0,z=0,k=j;while(k<n)p[k+=j]=0;while((x>>=1)>0)x&1>0?y++:z++;p[y]<1||p[z]<1?continue:j;}];
```
Nothing crazy. Essentially a modified sieve of Eratosthenes that evaluates the primality of the 0 / 1 count in the same iteration as crossing out higher non-primes. With some whitespace:
```
function f(n, ?p)
  return [ for (j in (p = [ for(i in 0...++n) i < 2 ? 0 : i ]))
    if (j > 0){
      var x = j * 2, y = 0, z = 0, k = j;
      while (k < n)
        p[k += j] = 0;
      while((x >>= 1) > 0)
        x & 1 > 0 ? y++ : z++;
      p[y] < 1 || p[z] < 1 ? continue : j;
    }
  ];
```
But today I learned I could put `continue` in a ternary operator and Haxe doesn't even mind.
Edit: +2 because `n` is an inclusive upper bound!
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + GNU utilities, ~~129~~ ~~126~~ ~~123~~ ~~114~~ ~~111~~ 109 bytes
```
seq '-fp()([ `factor|wc -w` = 2 ]);g()(dc -e2o${n}n|tr -cd $1|wc -c|p);n=%.f;p<<<$n&&g 0&&g 1&&echo $n' $1|sh
```
[Try it online!](https://tio.run/nexus/bash#HYqxDoMgGAZf5RsoykAjJp3AJ2lMbH5Bpx@qJg7SZ0ftcsPdldV/UemQalW/MYQPbXHJO0HvAzq06JWdrjZexrdRHPzjvC3QNEKY/0g5Kcvd4xlscs4JlnJCc8NI6WmOEFzd8zqXUsyrOQE "Bash – TIO Nexus")
Noticed the comment that the output doesn't have to be in increasing order -- shaved off 3 bytes by counting down instead of counting up.
Replaced grep with wc to save 3 additional bytes.
Eliminated a variable (9 more bytes off).
Changed the way factor is used -- 3 more bytes.
Made it golfier with seq (2 bytes).
[Answer]
# [Perl 6](http://perl6.org/), 50 bytes
```
{grep {($_&+.base(2).comb(~0&~1)).is-prime},0..$_}
```
Variation of [b2gills' answer](https://codegolf.stackexchange.com/a/107079/14880), using the `&` [junction](https://docs.perl6.org/type/Junction) operator to great effect.
[Try it online!](https://tio.run/nexus/perl6#Ky1OVSgz00u25uLKrVRQS1Ow/V@dXpRaoFCtoRKvpq2XlFicqmGkqZecn5ukUWegVmeoqamXWaxbUJSZm1qrY6CnpxJf@784sVIhTcHQ1OA/AA "Perl 6 – TIO Nexus")
### How it works
```
{                                                }  # Lambda
                                            0..$_   # Range from 0 to the lambda argument.
 grep {                                   },        # Filter values satisfying:
       ($_                      ).is-prime          #  a) The Number itself is prime.
       (   +.base(2).comb(~0   )).is-prime          #  b) The count of 0's is prime.
       (   +.base(2).comb(   ~1)).is-prime          #  c) The count of 1's is prime.
          &                 &                       # Junction magic! :)
```
[Answer]
## Python, ~~172~~ ~~170~~ ~~168~~ ~~159~~ ~~154~~ ~~133~~ 130 bytes
```
p=lambda n:[i for i in range(1,n)if n%i==0]==[1]
lambda n:[i for i in range(n+1)if p(i)*all(p(bin(i)[2:].count(x))for x in'10')]
```
---
Usage: Call the anonymous lambda function  
Method `p` checks whether a number is prime 
---
Saved 2+2+9=13 bytes thanks to Gurupad Mamadapur  
Saved 5 bytes thanks to mbomb007
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 14 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
ò≥úû╙2ï⌡T5è╧²■
```
[Run and debug it](https://staxlang.xyz/#p=95f2a396d3328bf554358acffdfe&i=10%0A100%0A150&a=1&m=2)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 14 bytes
```
'bĊvtJ₅3=$væA∧
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%27b%C4%8AvtJ%E2%82%853%3D%24v%C3%A6A%E2%88%A7&inputs=100&header=&footer=)
```
'              # (implicitly convert to range), then filter by...
 b             # Binary representation
  Ċ            # Count the amount of each value in a (1 & 0 only)
   vt          # Get the counts
     J         # Join the current number to each of those
      ₅        # Duplicate and get length
       3=      # Is it equal to 3?
         $     # Swap
          væA  # Are all prime?
             ∧ # Are both true?
```
[Answer]
## Pyke, 21 bytes
```
S#j_PI\0[jb2R/_P)I\1[
```
[Try it here!](http://pyke.catbus.co.uk/?code=S%23j_PI%5C0%5Bjb2R%2F_P%29I%5C1%5B&input=150&warnings=0)
```
S#j                   - for j in filter(range(1, input+1))
   _PI                -  if is_prime(j):
        [jb2R/_P)     -   function_[(a) = V
         jb2          -      base_2(j)
            R/        -     ^.count(a)
      \0         I    -   if function_[("0"):
                  \1[ -    function_[("1")
```
[Answer]
## Groovy, 120 bytes
```
p={x->(2..<x).every{x%it!=0}&x>1|x==2}
{x->(1..x).findAll({y->p(y)&'10'.every{p(Integer.toBinaryString(y).count(it))}})}
```
This is an unnamed closure.
[Try it here!](http://ideone.com/LWnXW3)
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 18 bytes
```
f.APM_M+T/LSjT2U2S
```
[Try it online here](http://pyth.herokuapp.com/?code=f.APM_M%2BT%2FLSjT2U2S&input=100&debug=0).
[Answer]
# [Python 3](https://docs.python.org/3/), 97 bytes
```
def f(n,k=2,m=1,p={0}):f(n-1,k+1,m*k*k,p^{m%k*k,{*map(bin(m%k%n*k)[2:].count,'01')}<p==print(k)})
```
This is the same algorithm as in [my Python 2 answer](https://codegolf.stackexchange.com/a/107073/12012), but the implementation is quite different. The function prints to STDOUT and terminates with an error.
[Try it online!](https://tio.run/nexus/python3#FchNCsJADEDhq7gpTcZUJgU3xZxEKvg3UMLEUOpqmLOPdfe@117vdEhgpDJSFiaXEitO@xqY9MiUgwYlv5Xc/aOEfHd4LAa7OwuK13GaT8/P1zbqI/dYLy7i62IbKFZsCfgcsf0A "Python 3 – TIO Nexus")
[Answer]
# JavaScript (ES6), 110 bytes
```
B=n=>n?B(n>>1,v[n%2]++):v.every(n=>(P=i=>n%--i?P(i):1==i)(n))
F=(n,a=[])=>n?F(n-1,B(n,v=[0,0,n])?[n,...a]:a):a
```
```
B=n=>n?B(n>>1,v,v[n%2]++):v.every(n=>(P=i=>n%--i?P(i):1==i)(n))
F=(n,a=[])=>n?F(n-1,B(n,v=[0,0,n])?[n,...a]:a):a
const update = () => {
  console.clear();
  console.log(F(input.value))
}
input.oninput = update;
update();
```
```
<input id="input" type="number" min="1" value="100" />
```
[Answer]
# **MATLAB, 50 bytes**
```
@(n)all(isprime([n,sum(de2bi(n)),sum(~de2bi(n))]))
```
[Answer]
# Haxe, ~~158~~ 147 bytes
```
function p(n,x=1)return n%++x<1||n<2?x==n:p(n,x);function f(n){var q=n,t=0,o=0;while(q>0){t++;o+=q%2;q>>=1;}p(n)&&p(o)&&p(t-o)?trace(n):0;f(n-1);};
```
Outputs to STDOUT and terminates on a "too much recursion" error; call with e.g. `f(1000);`. You can use a `while` loop with no error for 156 bytes:
```
function p(n,x=1)return n%++x<1||n<2?x==n:p(n,x);function f(n){while(n>0){var q=n,t=0,o=0;while(q>0){t++;o+=q%2;q>>=1;}p(n)&&p(o)&&p(t-o)?trace(n):0;n--;}};
```
Using a range turned out three bytes longer:
```
function p(n,x=1)return n%++x<1||n<2?x==n:p(n,x);function f(n){for(i in 0...n+1){var q=i,t=0,o=0;while(q>0){t++;o+=q%2;q>>=1;}p(i)&&p(o)&&p(t-o)?trace(i):0;}};
```
[Test it online!](http://try.haxe.org/#70094)
[Answer]
# Rust, 147 bytes
```
fn f(x:u32){let p=|n|n>1&&(2..n).all(|x|n%x!=0);for n in 9..x+1{if p(n)&&p(n.count_ones())&&p(n.count_zeros()-n.leading_zeros()){print!("{} ",n)}}}
```
[playground link](https://is.gd/zkedvo)
The `count_ones`, `count_zeros`, and `leading_zeros` methods came in handy.
### Formatted version
```
fn f(x: u32) {
    // primality test closure using trial division
    let p = |n| n > 1 && (2..n).all(|x| n % x != 0);
    for n in 9..x + 1 {
        if p(n) && p(n.count_ones()) && p(n.count_zeros() - n.leading_zeros()) {
            print!("{} ", n)
        }
    }
}
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 16 bytes
```
↑<⁰foΛṗo§e#0Σḋİp
```
[Try it online!](https://tio.run/##AScA2P9odXNr///ihpE84oGwZm/Om@G5l2/Cp2UjMM6j4biLxLBw////MTA "Husk – Try It Online")
]