Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 928711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:03:19+00:00 2026-05-15T20:03:19+00:00

I’m re-writing some old application in VB.NET to C# and ASP.NET 3.5. Everything is

  • 0

I’m re-writing some old application in VB.NET to C# and ASP.NET 3.5. Everything is going OK but I have this problem – and, as the database will not be changed, I must find a solution to it.

The old app saves the list o desired days (from Sunday to Saturday) in a byte. This is the way it do it:

If chkDaily.Checked Then
            daysBitmask = 127    ' This is for a full week
        Else
            For i = 0 To chklstWeekly.Items.Count - 1
                If chklstWeekly.Items(i).Selected Then
                    ' List the selected items
                    daysBitmask += 2 ^ CInt(chklstWeekly.Items(i).Value)
                    daysBitmask = daysBitmask
                    Message2.InnerText = daysBitmask
                End If
            Next
        End If

and I converted it to

        if (rdbDaysList.SelectedValue == DAILY)
            daysBitmask = 127;
        //This is for a full week
        else
            foreach (var d in ckbDaysList.Items)
            {
                ListItem day = d as ListItem;
                if (day.Selected)
                {
                    daysBitmask += Convert.ToByte(Math.Pow(2, Convert.ToDouble(day.Value)));
                }
            }

This works. My biggest problem is to convert from the byte to the C# code.
The original VB.NET is right above:

            If (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 AD As Integer = dr("DesireDays").ToString()
                Dim i As Integer

                For i = 0 To chklstWeekly.Items.Count - 1
                    If AD And 2 ^ i Then
                        chklstWeekly.Items(i).Selected = True

                    End If
                Next i

Any help will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:03:20+00:00Added an answer on May 15, 2026 at 8:03 pm

    You don’t want to use ToDouble, as you want an int (that’s what CInt gives you).

    In addition, for doing powers of two, bitshifting is usually a little clearer than doing exponents (though choose whatever works for you).

    As an aside, it’s also usually safer to use a bitwise OR (the vertical | bar) rather than addition.

    ListItem day = d as ListItem;
    
    if (day.Selected)
    {
        daysBitmask |= 1 << Convert.ToInt32(day.Value);
    }
    

    To answer the actual question, the reverse will work:

    ListItem day = d as ListItem;
    
    if ((daysBitmask & (1 << Convert.ToInt32(day.Value))) > 0)
    {
        day.Selected = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a reasonable size flat file database of text documents mostly saved in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.