Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I have a BitArray which I need to flip. In C++ you can just use the following syntax:

C++
bitset<5> MyBitset (mystring);
MyBitset.flip();


How can I achieve the same result in C#? Also, I now need to take this bitset (well, BitArray in C#) and convert it to a double. In C++ I can just us the .to_ulong() method, however, C# does not give me that option :/

Any help will be awesome!

Thanks in advance.
Posted
Comments
LanFanNinja 24-Nov-11 16:48pm    
Check solution below

1 solution

Use the Not() method of the BitArray class.

Edit: Here is a link for info about BitArray
http://msdn.microsoft.com/en-us/library/system.collections.bitarray.aspx[^]
Edit 2: You may want to check out the BitConverter class maybe it can help to convert BitArray to double.
 
Share this answer
 
v4
Comments
Espen Harlinn 24-Nov-11 17:12pm    
Good reply :)
LanFanNinja 24-Nov-11 17:13pm    
Thank you
DominicZA 24-Nov-11 17:15pm    
I need to reverse the order of the bits, this wont work! I have made a solution for this though!

BitConverter doesnt have an overload that takes a bool[], which is what a BitArray is.
LanFanNinja 24-Nov-11 17:19pm    
Well as far as I know the flip() function of bitset does not do this either!
You need to be more clear when posting question.
DominicZA 24-Nov-11 17:51pm    
as I said, that is no longer the issue! I know need to convert the bit array to a double

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900