1

I am trying to preform a simple bitwise statement to see if a user has security. It seems to be ok until i introduce variables.

This Works: byte test = 1 & 3.

Won't work: byte a = 1; byte b = 3; byte test = a & b;

Is there anyway that I can get this to work?

4
  • 1
    Define "won't work". What is your specific problem? Commented Aug 7, 2013 at 1:21
  • The error I get is: Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?) Commented Aug 7, 2013 at 1:25
  • That error actually tells you 1) what's wrong, and 2) what to do about it. Commented Aug 7, 2013 at 14:29
  • I've never had to cast something in C# i'm still learning. But next time i'll know what to do :) Commented Aug 7, 2013 at 21:23

1 Answer 1

4

You need to cast it back to a byte as a bitwise AND will return an int, so do this:

byte a = 1; byte b = 3; byte test = (byte)(a & b); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.