bitarray

Is there a generic (type-safe) BitArray in .NET?

泪湿孤枕 提交于 2019-12-22 07:52:13
问题 Is there a generic BitArray in .NET? I only found the non-generic one. Can there be a generic BitArray? (i.e. would it be reasonable?) Edit: Maybe I should have said type-safe not generic. Basically when you enumerate the type as object , should it not be int or bool ? Or one of them provided in another member enumerator? Example: foreach (bool bit in myBitArray) { } Edit: I just checked the enumerator of the BitArray class, but everything returns an object except .Current property: public

Is there a generic (type-safe) BitArray in .NET?

我的梦境 提交于 2019-12-22 07:51:25
问题 Is there a generic BitArray in .NET? I only found the non-generic one. Can there be a generic BitArray? (i.e. would it be reasonable?) Edit: Maybe I should have said type-safe not generic. Basically when you enumerate the type as object , should it not be int or bool ? Or one of them provided in another member enumerator? Example: foreach (bool bit in myBitArray) { } Edit: I just checked the enumerator of the BitArray class, but everything returns an object except .Current property: public

Performance improvement for mirroring bit matrix around the diagonal

▼魔方 西西 提交于 2019-12-22 05:20:24
问题 I have some code that manages data received from an array of sensors. The PIC that controls the sensors uses 8 SAR-ADCs in parallel to read 4096 data bytes. It means it reads the most significant bit for the first 8 bytes; then it reads their second bit and so on until the eighth (least significant bit). Basically, for each 8 bytes it reads, it creates (and sends forth to the computer) 8 bytes as follows: // rxData[0] = MSB[7] MSB[6] MSB[5] MSB[4] MSB[3] MSB[2] MSB[1] MSB[0] // rxData[1] = B6

Bit Array Equality

老子叫甜甜 提交于 2019-12-21 17:03:31
问题 I need something a little more than the System.Collections.BitArray class in my application. Specifically, I need the bit array: To be immutable To implement equality using value semantics I created my own struct , largely copying the internals of the BitArray implementation. (Thanks, .Net Reflector!) I don't deal everyday with bitwise operations, so I don't have the highest degree of confidence in my equality implementation. (It's passing the unit tests I am throwing at it, but I may be

What's a time efficient algorithm to copy unaligned bit arrays?

人走茶凉 提交于 2019-12-21 01:46:22
问题 I've had to do this many times in the past, and I've never been satisfied with the results. Can anyone suggest a fast way of copying a contiguous bit array from source to destination where both the source and destination's may not be aligned (right shifted) on convenient processor boundaries? If both the source and destination's aren't aligned , the problem can quickly be changed into one where only either of them aren't aligned (after the first copy say). As a starting point, my code

Shifting a BitArray

本小妞迷上赌 提交于 2019-12-20 06:42:38
问题 I'm currently trying to shift a BitArray while keeping its length. Since there's no built-in method I'm struggling to build one but can't make it work, unfortunatly. My initial BitArray code sets a length of 421 for the BitArray. var b = new BitArray(length: 421); Than, I'm assigning some values for testing. For instance: b.Set(0, true); b.Set(1, true); However, I can't figure out how to shift the bit array. Attempts: - I thought that I could convert it into long and than make the bit

C# - Shifting and reversing the order of bits in a byte array

南笙酒味 提交于 2019-12-20 05:57:45
问题 I am trying to get the correct int out of an array of bytes. The bytes is read from a RFIDTag via POS for .Net. (Acctually I need 18 bits) In binary the byte array is as follows: 00001110 11011100 00000000 00011011 10000000 What I need to get out of it is: 00 00000000 11101101 (int = 237) From the original bytes that would be the following bits in reverse order: ------10 11011100 00000000 I have been looking at bitArray. Array.Reverse. And several ways of shifting bits. But I just can't wrap

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

拈花ヽ惹草 提交于 2019-12-19 03:22:25
问题 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

BitArray returns bits the wrong way around?

有些话、适合烂在心里 提交于 2019-12-17 12:48:10
问题 This code: BitArray bits = new BitArray(new byte[] { 7 }); foreach (bool bit in bits) { Console.WriteLine(bit ? 1 : 0); } Gives me the following output: 11100000 Shouldn't it be the other way around? Like this: 00000111 I am aware that there is little and big endian, although those terms only refer to the position of bytes. As far as I know, they don't affect bits. 回答1: The documentation for BitArray states: The first byte in the array represents bits 0 through 7, the second byte represents

BitArray - Shift bits

蹲街弑〆低调 提交于 2019-12-17 07:49:53
问题 I have a System.Collections.BitArray array (~3000 items) and I would like to shift all the bits to the left by 1. However the collection doesn't seem to support that operation (i.e. bitArray << 1 not working and there is no method). Any idea on how to do that? Thanks! 回答1: This simple snippet shows a manual way to do it. The value of bitArray[0] is overwritten: //... bitArray is the BitArray instance for (int i = 1; i < bitArray.Count; i++) { bitArray[i - 1] = bitArray[i]; } bitArray[bitArray