How to write this in c# ?

ulaho

Registered Member
Joined
Aug 4, 2013
Messages
76
Reaction score
27
I have a function like this which would work in python:
xtime = lambda a: (((a << 1) ^ 0x1B) & 0xFF) if (a & 0x80) else (a << 1)

How to implement same idea in c# ?
I get errors, if I write this like that:

int xtime(int x)
{
if (x & 0x80)
{
return (((x << 1) ^ 0x1B) & 0xFF);
}
return x << 1;
}
Can some help with this xtime implementation?
 
Try: Convert.ToBoolean(x & 0x80)

You can't test an integer against a boolean.

I found a way how to make it work.
when I change (x & 0x80) to ((x & 0x80) != 0) I get the desired result.

Problem Solved.
 
Back
Top