in reply to Re: hex(unpack("H*")) help?!?!
in thread hex(unpack("H*")) help?!?!

Nope, that converts the string in the wrong byte order. that won't work at all. Note that '$1' and '$2' were bytes from a file, not integers from a file?

Replies are listed 'Best First'.
Re: Re: Re: hex(unpack("H*")) help?!?!
by davorg (Chancellor) on Oct 31, 2002 at 17:14 UTC

    Ah. OK. Is the string always two chars long?

    $number = hex("0x". reverse $string);

    (please don't take this suggestion seriously)

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      I think you need to do some reading. reverse doesn't work how you think either... reverse "ab" is "ab" ... sorry.

        Er... the result of reverse "ab" varies according to the context it is evaluated in. The concaternation operator evaluates it in scalar context.

        $ perl -le 'print "0x" . reverse "ab"' 0xba

        I'm not saying my solution is a good idea, but I do know how reverse works :)

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re: Re: hex(unpack("H*")) help?!?!
by jettero (Monsignor) on Oct 31, 2002 at 17:14 UTC
    I also checked... presuming the $string was "6801" instead of "\x68\x01" to see if it would work anyway... it does not. try it...
    perl -e '$i = hex("0x6801"); print sprintf("\%x", $i), "\n"'
    Still wrong. It should return 168, not 6801