0

So I'm translating some java to c# here is a example bit

// bits = 12 bit number
int bits = table[index];

if (bits & 1)
{...}

if (bits & 2)
{...}

if (bits & 3)
{...}

ect

the bits & # bit errors because of

Cannot implicitly convert type 'int' to 'bool'

I understand the error, i'm just not sure how to convert the bits & # bit to c# safe code, anyone know how it should be?

Thank you.

1
  • Java != JavaScript... Commented Dec 24, 2016 at 23:47

1 Answer 1

1

Easy, just compare the result with 0.

Some C based languages treat 0 as false and other values as true. But that is not true for c#

if ((bits & 2) !=0 )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.