in reply to Re: Re^3: IP Header
in thread IP Header

In addition to the problems Aristotle outlined above, there is one more problem. The functions unpack("b") and vec() unpack the bits in the wrong order within bytes.

If you unpack("B*", $foo), you will get all the bits (as a string) in the right order. Here is one way to get your final answer, although I'm not sure that eval "0b$_" is the best solution:

($ver, $hlen, $tos, $len) = map { eval "0b$_" } unpack "A4A4A8A16", un +pack("B*", $a);

Replies are listed 'Best First'.
Re: B versus b
by Aristotle (Chancellor) on Nov 03, 2002 at 14:36 UTC
    ++ for pointing out the B vs b concern, but you're wrong about vec. And that code is an eval $REDFLAG;, you should do it thusly: my ($ver, $hlen, $tos, $len) = map pack "B*", unpack "A4A4A8A16", unpack "B*", $foo; However, that will not honour the network byte ordering in $len.

    Makeshifts last the longest.