Question

I am making making an application in vb.net that will read files using a byte array as buffer, and create parity files for them by xoring the data... What would be the most efficient way of xoring a byte array? I have though of convertinbg the byte array to a bitarray and then run it trough an xor operation and turn it back to a byte array, but that sounds like a very processing expensive task, and i am worried that it might impact read/write speed... is there a better way to do this? thanks...

To avoid confusion: What the application does is read half the file to location 1, the other half to location 2, then a parity (xor of the two parts) to location 3...

Was it helpful?

Solution

To Xor two byte arrays simply use a for loop and the Xor operator.

VB.Net's Xor will compile to a the CIL Xor opcode which should be subsequently JIT compiled to the very fast x86 XOR processor instruction.

The cost of the Xor operation is likely to be negligible in comparison to the cost of file I/O.

OTHER TIPS

Depending on what you mean by "efficient" I think you can do better than a simple loop. My initial though is to break the processing into multiple threads. so it will complete faster. You know the size of the input array and therefore the output array so it would be easy to divide load and let each thread fill the appropriate part of the result.

There is a C# article on code project that does similar. Binary operations on byte arrays withparallelism

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top