[Update 10 Feb 2010: This code is C#]
public bool CheckMsgValid(byte[] _myArray, int _myIdx) {
bool t;
t = ((_myArray[_myIdx] & 0x80) == 0x80) ? true : false;
return t;
}
...which is basically the long way to write:
public bool CheckMsgValid(byte[] b, int x) {
return b[x] & 0x80 != 0 ;
}
I guess the original coder wanted to make double-sure that the two values were equal.
erm, not this?
ReplyDeletereturn b[x] & 0x80;
I should have mentioned, the code above was C#, not C. Because of the increased type safety, just "b[x] & 0x80" wouldn't return a bool.
ReplyDeleteSo what does _myArray[_myIdx] & 0x80 mean in C# and why is it superfluous in your code? I thought it was some bit masking.
ReplyDeleteIt is bitmasking. Then the "==" compares the mask and produces a bool.
ReplyDeleteI'm puzzled. Suppose in b[x] the value 129 (0x81) is stored. What are the results of both functions?
ReplyDeleteAh, you're right. I had a typo above. Fixed.
ReplyDeleteIn the meantime I installed a C# compiler on my linux box. And it wasn't happy with that either. Maybe: return (b[x] & 0x80) != 0 ;
ReplyDelete