chewbacca chewbacca - 2 years ago 69
Perl Question

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't numeric in numeric ne (!=)

Am I supposed to convert $data first?

Answer Source

Why are you using strings for binary operations?

Use ($data & 0x100) != 0 and, if necessary, convert $data to a number.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download