c# - Bitwise operations in Visual Basic .NET -


I am retyping some older applications from VB.NET to C # and ASP.NET 3.5. Everything is recovering but I have this problem - and, as the database will not change, I should know about this solution.

The old application list Such a byte desired days (Saturday and Sunday) to do it:

  If chkDaily.Checked then daysBitmask = 127 'it is for or a full week i = 0 chklstWeekly.Items.Count - 1 then chklstWeekly.Items (i) .Selected then selected items list daysBitmask + = 2 ^ CInt (chklstWeekly.Items (i) .Value) daysBitmask = daysBitmask Message2.InnerText = daysBitmask end of the next end is then converted to  

and I got it

  (if rdbDaysList.SelectedValue == daily) Daytime mask = 127; // This is for a full week's second bias (ckbDaysList.Items in var d) {ListItem day = d ListItem; If (day selected) {day bitmask + = convert ToByte (Math Pow (2, convert toDouble (day.Value))); }}  

This works to convert my biggest problem from byte into C # code. Basic VB.NET above right:

  are (Dr. ( "DesireDays") toString () = "127".) Then chkDaily.Checked = true chkWeekly.Checked = false chklstWeekly. Enabled = False Else chkWeekly.Checked = true chkDaily.Checked = false chklstWeekly.Enabled = true dim E as ToString (int = Dr ( "DesireDays")) i = 0 chklstWeekly.Items.Count for as low integer to - 1, AD and 2 ^ I chklstWeekly.Items (i) .Selected = true end I Next  

would appreciate any help.

After typing "itemprop =" text ">

you do not toDouble , as you would see a Want integer (what is the wants> CInt gives you).

In addition, to do the powers of the two, bitsfosting is usually a little bit clearer than the exponent (though whatever works for you).

As an aside, this is usually an extra, instead of a bitword or (vertical | ). ListItem day = D as ListItem; If (day selected) {daytime mask | = 1 & lt; & Lt; Convert.ToInt32 (day.Value); }

To answer the real question, the reverse will work:

  ListItem day = d as ListItem; If ((Duryatk Mask & amp; (1 & lt; & lt; Convert toInt32 (day.Value))) gt; {day.Selected = true; }  

Comments