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

將所有大小為 n 的二進(jìn)制字符串生成為布爾數(shù)組

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

問(wèn)題描述

例如,如果我想要所有長(zhǎng)度為 3 的二進(jìn)制字符串,我可以像這樣簡(jiǎn)單地聲明它們:

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};

將所有可能的長(zhǎng)度為 N 的二進(jìn)制字符串生成到 布爾數(shù)組中的最有效方法是什么?

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

我不一定需要最有效的方法,只需要一種對(duì)我來(lái)說(shuō)相當(dāng)有效且易于多線程的方法.

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

我應(yīng)該注意,如果這很重要,我會(huì)將它們?nèi)看鎯?chǔ)在一個(gè) ArrayList 中.

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

推薦答案

這是一些生成真值表的代碼...(由于數(shù)組大小限制,僅適用于 32 位(您可以將大小變量更改為任意值,并且如果需要,將布爾值存儲(chǔ)為 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();
    }

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

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 操一草 | 天天色av| 欧美成人精品 | 麻豆a级片 | 在线视频一区二区 | 成人在线中文字幕 | 精品一区二区久久久久久久网精 | 亚洲传媒在线 | 羞羞视频免费在线 | 国产成人自拍av | 日韩成人在线播放 | 欧美国产精品久久久 | 草久在线| 日本成人在线网址 | 久久一区 | 午夜精品在线观看 | 玖玖久久 | 91av亚洲| 一区二区三区四区在线 | 日韩视频精品 | 日韩精品久久久 | 日韩av中文| 国产美女一区二区 | 亚洲午夜精品在线观看 | 伊人最新网址 | 欧美亚洲视频 | 久草视频在线播放 | 精品国产欧美 | 国产成人99久久亚洲综合精品 | 国产清纯白嫩初高生在线播放视频 | 91精品久久久久久久久久 | 九九九视频在线 | 国产精品国产a级 | 丝袜 亚洲 另类 欧美 综合 | 日日操视频 | 97精品一区二区 | 97av视频| 亚洲精品电影网在线观看 | av中文字幕在线播放 | www.色综合| 日韩精品在线视频免费观看 |