Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Math.Pow(2,n) to store user's selections

Status
Not open for further replies.

KokasPapa

Programmer
Joined
Jan 26, 2007
Messages
2
Location
GB
Hello

I have a webform with a series of radiobuttons where a user can select which pages he will visit next after he hits a button.

I thought I'd store his selections like this:

Code:
private int SelectedSchemes()
{
 if ( rdSTEERY.Checked )
  iSelected += Convert.ToInt32(Math.Pow(2,1));
			
 if ( rdCAFEY.Checked )
  iSelected += Convert.ToInt32(Math.Pow(2,2));

 if ( rdDiscPlusY.Checked )
  iSelected += Convert.ToInt32(Math.Pow(2,3));

    .
    .
    .
    so on...
			
  return iSelected;
}

So if the user chooses yes on the first 2 radiobuttons then I'll be storing the value 6 in the database, which corresponds to the 1st and 2nd pages.
My problem is that I don't know how to translate this breaking down of this value to those webpages. Any ideas?

Thanks
 
Use an Enum with the flags option. This effectively allows you to name each bit, and will make your code a whole lot more readable as you can then use symbolic names rather than bit values.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top