Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes this type of function or technique have a name?
    text
    copied!<p>HI there, I'm slightly new to programming, more of a hobby. I am wondering if a the following logic or technique has a specific name, or term. My current project has 7 check boxes, one for each day of the week. I needed an easy to save which boxes were checked.</p> <p>The following is the method to saved the checked boxes to a single number. Each checkbox gets a value that is double from the last check box. When I want to find out which boxes are checked, I work backwards, and see how many times I can divide the total value by the checkbox value. </p> <pre><code>private int SetSelectedDays() { int selectedDays = 0; selectedDays += (dayMon.Checked) ? 1 : 0; selectedDays += (dayTue.Checked) ? 2 : 0; selectedDays += (dayWed.Checked) ? 4 : 0; selectedDays += (dayThu.Checked) ? 8 : 0; selectedDays += (dayFri.Checked) ? 16 : 0; selectedDays += (daySat.Checked) ? 32 : 0; selectedDays += (daySun.Checked) ? 64 : 0; return selectedDays; } private void SelectedDays(int n) { if ((n / 64 &gt;= 1) &amp; !(n / 64 &gt;= 2)) { n -= 64; daySun.Checked = true; } if ((n / 32 &gt;= 1) &amp; !(n / 32 &gt;= 2)) { n -= 32; daySat.Checked = true; } if ((n / 16 &gt;= 1) &amp; !(n / 16 &gt;= 2)) { n -= 16; dayFri.Checked = true; } if ((n / 8 &gt;= 1) &amp; !(n / 8 &gt;= 2)) { n -= 8; dayThu.Checked = true; } if ((n / 4 &gt;= 1) &amp; !(n / 4 &gt;= 2)) { n -= 4; dayWed.Checked = true; } if ((n / 2 &gt;= 1) &amp; !(n / 2 &gt;= 2)) { n -= 2; dayTue.Checked = true; } if ((n / 1 &gt;= 1) &amp; !(n / 1 &gt;= 2)) { n -= 1; dayMon.Checked = true; } if (n &gt; 0) { //log event } } </code></pre> <p>The method works well for what I need it for, however, if you do see another way of doing this, or a better way to writing, I would be interested in your suggestions.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload