Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Actually I can't solve this . please help me..........

Decimal Number : (23,24,25,26,27,28,29)
Binary Number of them :(10111,11000,11001,11010,11011,11100,11101)
Here same is 23,27,29 there are four '1' among this 23,27 and 29. If I input 23 then it will show a decimal number which also have four '1' and which is nearest from the other same (four '1') number.
Posted

1 solution

A combination of shift and logical operators will help you. See http://msdn.microsoft.com/en-us/library/y0c1cfax.aspx[^].
 
Share this answer
 
Comments
Rayhanuzzaman Roky 23-Aug-14 2:17am    
sorry sir I can't understand and solve my problem!
Richard MacCutchan 23-Aug-14 2:52am    
Sorry, but if you don't understand the basic operators in C then you are not going to get very far. You can count the number of bits in a value by testing the low or high order bit against a fixed value (0x01 for low and 0x80 for high). You then shift the value left or right as appropriate to move the next bit into that position and repeat until you have tested all bits.
Rayhanuzzaman Roky 23-Aug-14 5:26am    
thanks....... I know this but can't run this code something wrong and so that it is not working properly
Richard MacCutchan 23-Aug-14 6:17am    
something wrong and so that it is not working properly
That could mean anything. Edit your question and show the code and explain where it is not working.

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