bitarray

BitArray alternative for the .NET Micro Framework

泪湿孤枕 提交于 2019-12-01 07:02:26
问题 Is there a BitArray alternative for the .NET Micro Framework? I was thinking about simply using a bool[], but how can you convert it back into a byte[] ? In the full framework, considering "bits" is a BitArray, the following works: byte[] data = new byte[dimensions / 8]; bits.CopyTo(data, 0); But I cannot seem to find the BitArray class in the micro framework 回答1: It's not terribly difficult to duplicate the functionality of BitArray . First, if you need fewer than 65 bits, then you can do it

Unset the most significant bit in a word (int32) [C]

二次信任 提交于 2019-11-30 22:25:39
How can I unset the most significant setted bit of a word (e.g. 0x00556844 -> 0x00156844)? There is a __builtin_clz in gcc, but it just counts the zeroes, which is unneeded to me. Also, how should I replace __builtin_clz for msvc or intel c compiler? Current my code is int msb = 1<< ((sizeof(int)*8)-__builtin_clz(input)-1); int result = input & ~msb; UPDATE: Ok, if you says that this code is rather fast, I'll ask you, how should I add a portability to this code? This version is for GCC, but MSVC & ICC? Just round down to the nearest power of 2 and then XOR that with the original value, e.g.

python bit array (performant)

好久不见. 提交于 2019-11-30 20:45:01
I'm designing a bloom filter and I'm wondering what the most performant bit array implementation is in Python. The nice thing about Python is that it can handle arbitrary length integers out of the box and that's what I use now, but I don't know enough about Python internals to know if that's the most performant way to do it in Python. I found bitarray but it handles a lot of other things like slicing, which I don't need. I only need the & and | and << operations. The built-in int is pretty nicely optimized, and it already supports & , | , and << . There's at least one alternative

Slow bitwise operations

泄露秘密 提交于 2019-11-30 20:13:00
I am working on a Python library that performs a lot of bitwise operations on long bit strings, and I want to find a bit string type that will maximize its speed. I have tried the built-in Python int type, numpy, bitstring , and bitarray , and suprisingly, the Python ints seem to win hands down when it comes to bitwise operations. Everything I have googled says numpy should be much faster for vectorized operations like this. Am I using numpy wrong somehow? Is there another Python library I can use that actually improves on Python's built-in int type? from timeit import timeit import random

python bit array (performant)

耗尽温柔 提交于 2019-11-30 04:51:16
问题 I'm designing a bloom filter and I'm wondering what the most performant bit array implementation is in Python. The nice thing about Python is that it can handle arbitrary length integers out of the box and that's what I use now, but I don't know enough about Python internals to know if that's the most performant way to do it in Python. I found bitarray but it handles a lot of other things like slicing, which I don't need. I only need the & and | and << operations. 回答1: The built-in int is

Slow bitwise operations

拜拜、爱过 提交于 2019-11-30 03:49:13
问题 I am working on a Python library that performs a lot of bitwise operations on long bit strings, and I want to find a bit string type that will maximize its speed. I have tried the built-in Python int type, numpy, bitstring, and bitarray, and suprisingly, the Python ints seem to win hands down when it comes to bitwise operations. Everything I have googled says numpy should be much faster for vectorized operations like this. Am I using numpy wrong somehow? Is there another Python library I can

Fast code for searching bit-array for contiguous set/clear bits?

大憨熊 提交于 2019-11-29 07:04:12
Is there some reasonably fast code out there which can help me quickly search a large bitmap (a few megabytes) for runs of contiguous zero or one bits? By "reasonably fast" I mean something that can take advantage of the machine word size and compare entire words at once, instead of doing bit-by-bit analysis which is horrifically slow (such as one does with vector<bool> ). It's very useful for e.g. searching the bitmap of a volume for free space (for defragmentation, etc.). Windows has an RTL_BITMAP data structure one can use along with its APIs. But I needed the code for this sometime ago,

Converting C# byte to BitArray

拜拜、爱过 提交于 2019-11-29 05:58:19
Is there any predefined function available to convert a byte into BitArray ? One way would be to inspect every bit of the byte value and then perform bitwise operation. I was wondering if there is any way which is more straightforward than this. CodeCaster Yes, using the appropriate BitArray() constructor as described here : var bits = new BitArray(arrayOfBytes); You can call it with new BitArray(new byte[] { yourBite }) to create an array of one byte. if you have a byte number or even an integer, etc. BitArray myBA = new BitArray(BitConverter.GetBytes(myNumber).ToArray()); Note: you need a

Counting bits set in a .Net BitArray Class

余生长醉 提交于 2019-11-28 08:16:34
I am implementing a library where I am extensively using the .Net BitArray class and need an equivalent to the Java BitSet.Cardinality() method, i.e. a method which returns the number of bits set. I was thinking of implementing it as an extension method for the BitArray class. The trivial implementation is to iterate and count the bits set (like below), but I wanted a faster implementation as I would be performing thousands of set operations and counting the answer. Is there a faster way than the example below? count = 0; for (int i = 0; i < mybitarray.Length; i++) { if (mybitarray [i]) count+

Fast code for searching bit-array for contiguous set/clear bits?

蓝咒 提交于 2019-11-28 00:37:37
问题 Is there some reasonably fast code out there which can help me quickly search a large bitmap (a few megabytes) for runs of contiguous zero or one bits? By "reasonably fast" I mean something that can take advantage of the machine word size and compare entire words at once, instead of doing bit-by-bit analysis which is horrifically slow (such as one does with vector<bool> ). It's very useful for e.g. searching the bitmap of a volume for free space (for defragmentation, etc.). 回答1: Windows has