如何管理在C ++比特/二进制? [英] How can I manage bits/binary in c++?
问题描述
我需要做的是开放与0和1的文本文件,找到文件中的列之间的模式。
What I need to do is open a text file with 0s and 1s to find patterns between the columns in the file.
所以,我首先想到的是每一列解析成的bool的一大阵,然后再做列之间的逻辑(今阵列)。直到我发现布尔变量的大小实际上是一个字节不是有点,所以我会浪费内存的1/8,每个值赋值给一个布尔值。
So my first thought was to parse each column into a big array of bools, and then do the logic between the columns (now in arrays). Until I found that the size of bools is actually a byte not a bit, so i would be wasting 1/8 of memory, assigning each value to a bool.
它甚至在为800x800值的网格相关的?什么是处理这个的最佳方式?
我想AP preciate的情况下,code片段它是一个复杂的答案
Is it even relevant in a grid of 800x800 values? What would be the best way to handle this? I would appreciate a code snippet in case its a complicated answer
推荐答案
您可以使用的std ::矢量<布尔>
这是采用了紧凑载体的特存储布尔.... 1位不是8位。
you can use std::vector<bool>
which is a specialization of vector that uses a compact store for booleans....1 bit not 8 bits.
这篇关于如何管理在C ++比特/二进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!