We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
first you can take value from user and there is 3 point which you have to take care....
1-input should convert into binary
2-binary value have to flipp means where 1 put 0 and where 0 put 1
3-You got flipped number now again you have to convrt it into decimal ,the ligic are...
for (int i = arr.Length - 1; i >= 0; i--)
{
uint x = arr[i];
uint r = x;
if (x == 1)
{
value = Convert.ToUInt32(Math.Pow(2, i));
val += value;
}
else
{
if (r == 0)
{
}
else
{
value = Convert.ToUInt32(Math.Pow(0, i));
val += value;
}
}
}
this is in c# program ....you can do it in c and c++
Thank You
Swatantra Mishra
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping bits
You are viewing a single comment's thread. Return to all comments →
first you can take value from user and there is 3 point which you have to take care.... 1-input should convert into binary 2-binary value have to flipp means where 1 put 0 and where 0 put 1 3-You got flipped number now again you have to convrt it into decimal ,the ligic are... for (int i = arr.Length - 1; i >= 0; i--) {
this is in c# program ....you can do it in c and c++ Thank You Swatantra Mishra