久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將所有大小為 n 的二進制字符串生成為布爾數組

Fastest way to generate all binary strings of size n into a boolean array?(將所有大小為 n 的二進制字符串生成為布爾數組的最快方法?)
本文介紹了將所有大小為 n 的二進制字符串生成為布爾數組的最快方法?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

例如,如果我想要所有長度為 3 的二進制字符串,我可以像這樣簡單地聲明它們:

For example, if I wanted all binary strings of length 3 I could simply declare them like this:

boolean[] str1 = {0,0,0};
boolean[] str2 = {0,0,1};
boolean[] str3 = {0,1,0};
boolean[] str4 = {0,1,1};
boolean[] str5 = {1,0,0};
boolean[] str6 = {1,0,1};
boolean[] str7 = {1,1,0};
boolean[] str8 = {1,1,1};

將所有可能的長度為 N 的二進制字符串生成到 布爾數組中的最有效方法是什么?

What is the most efficient way to generate all possibly binary strings of length N into a boolean array?

我不一定需要最有效的方法,只需要一種對我來說相當有效且易于多線程的方法.

I don't necessarily need the most efficient method, just one that's fairly efficient and easy for me to multithread.

我應該注意,如果這很重要,我會將它們全部存儲在一個 ArrayList 中.

I should note that I will be storing them all in an ArrayList, if that matters.

推薦答案

這是一些生成真值表的代碼...(由于數組大小限制,僅適用于 32 位(您可以將大小變量更改為任意值,并且如果需要,將布爾值存儲為 1/0):

Here's some code to generate a truth table... (works for only for 32 bits because of array size limits ( you can change the size variable to whatever and store booleans as 1/0 if you want):

int size = 3;
    int numRows = (int)Math.pow(2, size);
    boolean[][] bools = new boolean[numRows][size];
    for(int i = 0;i<bools.length;i++)
    {
        for(int j = 0; j < bools[i].length; j++)
        {
            int val = bools.length * j + i;
            int ret = (1 & (val >>> j));
            bools[i][j] = ret != 0;
            System.out.print(bools[i][j] + "	");
        }
        System.out.println();
    }

這篇關于將所有大小為 n 的二進制字符串生成為布爾數組的最快方法?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: xx视频在线观看 | 丝袜一区二区三区 | 亚洲第一成人av | 武道仙尊动漫在线观看 | 免费一级片 | 狠狠操狠狠操 | 亚洲一区二区三区视频 | 99久久久无码国产精品 | 色就干 | 国产一区二区黑人欧美xxxx | 男人天堂网av | 欧美日韩亚洲国产 | 久久久精品一区二区三区 | 久久久91精品国产一区二区三区 | 韩日中文字幕 | 五月激情综合 | 成人在线观看中文字幕 | 日本91av视频| a在线免费观看 | 久久久精品视频一区二区三区 | 成人深夜福利网站 | 黄色在线观看网址 | 成人黄页在线观看 | av毛片在线播放 | av网站免费在线观看 | 福利一区在线观看 | 999久久久 | 欧美黄在线观看 | 欧美在线观看一区 | 求个av网址 | 国产探花在线精品一区二区 | 精品无码久久久久久国产 | 亚洲视频免费 | 男女黄网站 | 免费久草| 国产成人综合在线 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 亚洲午夜在线 | 欧美一区二区三区,视频 | 91亚洲精品久久久电影 | 在线播放第一页 |