C# Access level string to byte

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arggg
    New Member
    • Mar 2008
    • 91

    C# Access level string to byte

    I have a varchar in the database 52669 ( or something like that) that I store in a namecollection with other variables for user info and would like to change it to bytes so I can use bitwise to see if they have access level "1". What I need to do is change the Login._userInfo["Access"] from string to byte so I can do the bitwise to see if they have access however i get cannot use operator & with bytes[] or bytes when converting ["Access"] to ascii bytes.

    Can anyone help me with a simple method to check if byte 1 exists in byte #####
    here is what i have
    Code:
    			long can = StrToByteArray(Login._userInfo["Access"]) & _AXS_LOGIN_;
    			if (can == 0)
    			{
    				MessageBox.Show("You do not have access to use this application.\n\n"+
    					"Please have your supervisor grant you access!");
    				Environment.Exit(1);
    			}
    
    		// C# to convert a string to a byte array.
    		public static byte[] StrToByteArray(string str)
    		{
    			System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
    			return encoding.GetBytes(str);
    		}
    Here is the error I get
    Code:
    Error	1	Operator '&' cannot be applied to operands of type 'byte[]' and 'byte'
  • arggg
    New Member
    • Mar 2008
    • 91

    #2
    I got it to work by doing this.

    Code:
    if ((Convert.ToInt32(Login._userInfo["Access"]) & _AXS_LOGIN_) == 0)
    			{
    				MessageBox.Show("You do not have access to use this application.\n\n"+
    					"Please have your supervisor grant you access!");
    				Environment.Exit(1);
    			}

    Comment

    Working...