Logical Operation With byte[] -- What is it doing?
- From: Hal Vaughan <hal@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 22 Dec 2005 23:28:44 -0500
I'm going through someone else's GPL'ed code and trying to figure just what
it does. I don't think the whole routine is needed, here are the pertinent
lines:
byte[] bRawData;
int a, i;
//Bunch of other stuff, including reading a file into bRawData
//then, in a loop, I found:
a = bRawData[i] & 0xFF;
After this, the interger "a" is never used again. I *think* this line is
extraneous and was just left in when another section was removed. I've got
a few questions, just so I'm sure I know what is going on:
1) As I understand it, "bRawData" is not effected at all by this operation,
just as it would not be with any mathematical operation. Is this correct?
2) Isn't it pointless to AND a byte and 0xFF? Doesn't that just keep the
1's as 1's and 0's as 0's?
3) Am I correct that if "a" is not used after this and "bRawData" is not
effected, that this line is basically pointless?
I'm pretty sure that without "a" being used later, this line is pointless,
and, unless I misunderstand bit operations, I would think ANDing with 0xFF
would be pointless as well. I just want to make sure there isn't something
subtle I'm missing before I delete this line (or delete it or comment it
out, see tests that work, and find out weeks later that some subtle bug is
discovered and, by then, I've forgotten this issue).
Thanks for any insight!
Hal
.
- Follow-Ups:
- Re: Logical Operation With byte[] -- What is it doing?
- From: Steve Horsley
- Re: Logical Operation With byte[] -- What is it doing?
- From: Roedy Green
- Re: Logical Operation With byte[] -- What is it doing?
- Prev by Date: Re: Implementing the equals method
- Next by Date: Re: Logical Operation With byte[] -- What is it doing?
- Previous by thread: Implementing the equals method
- Next by thread: Re: Logical Operation With byte[] -- What is it doing?
- Index(es):