Binary bitmask
doozer
Posts: 4
Hi All,
I'm sure i'm doing something stupid here (my background is in C which tends to cause me problems when coding for netlinx), but I can't seem to use a binary integer when doing a bitmask comparison.
I'm receiving a char via serial and need to check if a bit (in this case bit 2) is set. I tried using:
if (receivedChr & 00000010b)
{
// do something
}
But it results in a compiler error:
ERROR: C10201: Syntax error; Illegal or Invalid syntax in code
Of course changing it to:
if (receivedChr & $02)
{
// do something
}
Compiles fine. My question is, how come I can't do a binary bitmask (it will make the code easier to understand)?
I have also tried declaring my binary value as a constant (which the docs seem to indicate is legal) but that too generates an error.
Thanks,
Matt.
I'm sure i'm doing something stupid here (my background is in C which tends to cause me problems when coding for netlinx), but I can't seem to use a binary integer when doing a bitmask comparison.
I'm receiving a char via serial and need to check if a bit (in this case bit 2) is set. I tried using:
if (receivedChr & 00000010b)
{
// do something
}
But it results in a compiler error:
ERROR: C10201: Syntax error; Illegal or Invalid syntax in code
Of course changing it to:
if (receivedChr & $02)
{
// do something
}
Compiles fine. My question is, how come I can't do a binary bitmask (it will make the code easier to understand)?
I have also tried declaring my binary value as a constant (which the docs seem to indicate is legal) but that too generates an error.
Thanks,
Matt.
0
Comments
A binary number is not an intinsic data type in Netlinx or C. You will have to use an integer or the hex equivalent, in your case, 2 or $02.
Paul
I have seen that several times when I ran through the help file, it has never worked. I think it was a "WISH" item from the beginning of time, just never got removed from the help file.
The help file does imply that binary notation is acceptable; however, as discovered that isn?t the case. An error in a help file, imagine that.
I shall move on with a hex bitmask.