bit manipulation - How to flip bits in C#? -


i have binary number in form of string as

string input = "10110101101"; 

now need flip (0 1 , 1 0) first 3 bits of it.

the resultant output 01010101101

how in c#?

an alternate way using convert.toint32, convert.tostring (which otherwise unknown , unused), , bitwise-xor

string input = "10110101101"; int flipno = 3; int output = convert.toint32(input, 2); (int = input.length - 1; >= input.length - flipno; --i)     output ^= 1 << i; 

simply use output, or if want display output in string, do:

string display = convert.tostring(output, 2).padleft(input.length, '0'); 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -