久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产精品久久久久久久久久久新郎 | 亚洲精品成人 | 日韩在线视频一区二区三区 | av永久| 国产xxx在线观看 | 一级黄色夫妻生活 | 亚洲高清免费视频 | 成人在线一级片 | 久久久久中文字幕 | 久久久久国产精品一区二区 | 国产成人艳妇aa视频在线 | 99免费精品视频 | 国产精品一区二区久久久久 | 毛片视频观看 | 老牛嫩草一区二区三区av | 国产一区二区三区 | 少妇性l交大片免费一 | 国产精品免费一区二区三区 | 人人做人人澡人人爽欧美 | 中文字幕一区二区在线观看 | 亚洲36d大奶网 | 久久不卡 | 一级在线免费观看 | 91久久精| 亚洲综合无码一区二区 | 久久高清 | 亚洲一区二区久久 | 日本淫视频 | 成人免费看 | 亚洲成人一区 | 午夜专区 | 91视频进入 | 伊人网影院 | 2021狠狠干 | 精品一区二区三区四区在线 | 91在线最新 | 久久999 | 亚洲成人综合社区 | 成人av一区二区在线观看 | 一区中文字幕 | 性生生活大片免费看视频 |