Search: in  

zip BitVector64 Structure

Downloads: 16 File Size: 19.2kB
Posted By: RobK410 Views: 500
Date Added: 08-30-2007

Ok, so I wrote about a nifty little structure I found within the .NET framework and in doing some searching found that there did not exist a BitVector64 anywhere. So being bored, and figuring it would only take me a couple hours, I went ahead and did an implementation of a 64 bit version of the BitVector32 structure. Mine will allow you to set a 64 bit value, and find the bit value for all 64 bits, as well as use a (ushort) Section bit mask if you really want to (not sure why) So here it is, source code included... I'm sure there's something wrong with it, but I know the bit checking works flawlessly!

Please feel free to leave feedback if you find this code useful. Perhaps Microsoft will include it in their next C# release!

-Rob

Sample Usage:

   1: using RobKennedy.BitVectors;            
   2: ...
   3:  
   4: // Simplest Test of BitVector64
   5: BitVector64 newVec = new BitVector64(Convert.ToInt64(maskedTextBox1.Text));
   6:  
   7: // check to see if bit 32 is set (33rd bit if counting from 1)            
   8: if (newVec[32])
   9:     MessageBox.Show("We are bigger than a dword because bit 32 is on!");
  10:  
  11: ...

Here's another example provided by a BitVector64 user:

   1: BitArray Arr = new BitArray(32); 
   2: BitVector64 Arr64 = new BitVector64(); 
   3: BitVector32 Arr32 = new BitVector32(); 
   4: int iter = 100000000; 
   5: DT1 = DateTime.Now; 
   6: for (int i = 0; i < iter; i++) 
   7:     Arr[0] = true; 
   8:  
   9: Console.WriteLine("Elapsed:(Arr) " + DateTime.Now.Subtract(DT1).ToString()); 
  10:  
  11: DT1 = DateTime.Now; 
  12: for (int i = 0; i < iter; i++) 
  13:     Arr64[0] = true; 
  14:  
  15: Console.WriteLine("Elapsed:(Arr64) " + DateTime.Now.Subtract(DT1).ToString()); 
  16:  
  17: DT1 = DateTime.Now; 
  18: for (int i = 0; i < iter; i++) 
  19:     Arr32[0] = true; 
  20:  
  21: Console.WriteLine("Elapsed:(Arr32) " + DateTime.Now.Subtract(DT1).ToString()); 
  22:  
  23: DT1 = DateTime.Now; 
  24:  
  25: //here is the result: 
  26: //Elapsed:(Arr) 00:00:01.5312500 
  27: //Elapsed:(Arr64) 00:00:01.1718750 
  28: //Elapsed:(Arr32) 00:00:00.6093750 
Share this post: E-mail BitVector64+Structure | Submit BitVector64+Structure to Technorati | Submit BitVector64+Structure to del.icio.us | Submit BitVector64+Structure to digg.com | Submit BitVector64+Structure to reddit.com | Submit BitVector64+Structure to DotNetKicks | Add BitVector64+Structure to Live Bookmarks

Comments

 

murat said:

Hi, thank you very much for your code. I made a little test and it works very fast here is the test code: ... BitArray Arr = new BitArray(32); BitVector64 Arr64 = new BitVector64(); BitVector32 Arr32 = new BitVector32(); ... iter = 100000000; DT1 = DateTime.Now; for (int i = 0; i < iter; i++) Arr[0] = true; Console.WriteLine("Elapsed:(Arr) " + DateTime.Now.Subtract(DT1).ToString()); DT1 = DateTime.Now; for (int i = 0; i < iter; i++) Arr64[0] = true; Console.WriteLine("Elapsed:(Arr64) " + DateTime.Now.Subtract(DT1).ToString()); DT1 = DateTime.Now; for (int i = 0; i < iter; i++) Arr32[0] = true; Console.WriteLine("Elapsed:(Arr32) " + DateTime.Now.Subtract(DT1).ToString()); DT1 = DateTime.Now; ... here is the result: .. Elapsed:(Arr) 00:00:01.5312500 Elapsed:(Arr64) 00:00:01.1718750 Elapsed:(Arr32) 00:00:00.6093750 again thank you very much..
10-06-2007 3:30 AM
 

murat said:

uppps! I didnt know html is disabled. the code seems terrible
10-06-2007 3:33 AM
 

dest said:

Very nice ... thank you for creating this. any chance next time you get bored a 96bit one might come about? :)
11-20-2007 7:46 AM
Copyright © 2007, RobKennedy.com.
I reserve the right to beat yo arse if you steal sh!t.
Shat out at you via the CommunityServer.org Engine