Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store long binary (up to 512 bit) in C#

I'm trying to figure out the best way to store large binary (more than 96 bit) numbers in C#

I'm building application that will automatically allocate workers for shifts. Shifts can be as short as 15 minutes (but this might be even smaller in the future). To avoid double-booking of workers, I plan to have binary map of their daily time: 24 hours separated in equal chunks (15 minutes) and every chunk has a flag (0 for free, 1 for busy) So when we try to give another shift to a worker, we can do binary comparison of workers daily availability with shift's time. Simple and easy to decide.

But C# long only allows to have up to 64 bit, and with the current set up I need at least 96 bits (24 hours * 60 minutes / 15 minutes per period). This representation must be memory friendly, as there will be about a million objects operated at a time.

Few other options i considered:

  • String. Memory-hungry, not simple to implement bit-wise operations
  • Array of bits. But as far as I know C# does not have bit type
  • Array of unsigned integers. Each array represents only part of a day. The best I can think of

Any other suggestions??

Thanks in advance!

like image 930
trailmax Avatar asked Dec 12 '22 11:12

trailmax


2 Answers

Have you looked at the BitArray class? It should be pretty much exactly what you're looking for.

like image 111
Brandon Moretz Avatar answered Dec 28 '22 22:12

Brandon Moretz


Try following,

.Net 4 has inbuilt BigInteger type

http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx

.Net 2 project on code project http://www.codeproject.com/KB/cs/biginteger.

Another alternative, http://www.codeplex.com/IntX/

like image 35
Akash Kava Avatar answered Dec 28 '22 20:12

Akash Kava