Get the sum of powers of 2 for a given number + c#

Viewed 6439

I have a table with different codes. And their Id's are powers of 2. (20, 21, 22, 23...). Based on different conditions my application will assign a value to the "Status" variable. for ex :

Status = 272 ( which is 28+ 24)
Status = 21 ( Which is 24+ 22+20)

If Status = 21 then my method (C#) should tell me that 21 is sum of 16 + 4 + 1.

5 Answers
Related