Do I need to pack/unpack data read from a binary file before performing bitwise operations?
I've read two bytes from a binary file into $data and now need to perform a bitwise and.
But when I do
if (($data & "\x100") != 0) {
I get the error Argument "@\0" isn'开发者_StackOverflow社区t numeric in numeric ne (!=)
Am I supposed to convert $data first?
Why are you using strings for binary operations?
Use ($data & 0x100) != 0
and, if necessary, convert $data
to a number.
Yes, if you have two literal bytes which should be interpreted as a 16-bit number, you need to unpack it.
On top of that, what ThiefMaster said.
精彩评论