Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

packing and unpacking

by ungalnanban (Pilgrim)
on Mar 12, 2010 at 09:15 UTC ( #828246=perlquestion: print w/ replies, xml ) Need Help??
ungalnanban has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I want to get output as 0x23400000345....
in the below example
How to get?
i tried out, but unable to get the answer

$r=0x234; $t=0x345; $y=pack('L L',$t,$r); $x1=unpack('L!',pack('P',$y)); printf("\nThe value is $x1");

I didn't get constant output

--sugumar--

Comment on packing and unpacking
Download Code
Re: packing and unpacking
by almut (Canon) on Mar 12, 2010 at 09:40 UTC
    my $r = 0x234; my $t = 0x345; my $y = pack('L L', $t, $r); my $x1 = unpack('Q', $y); printf "\nThe value is 0x%x", $x1; # 0x23400000345

    (in case you have a 64-bit perl)


      I don't know the 64-bit Perl.
      whether you are mentioning 64-bit processor or ...?

      I am using Perl version 5.8.8

      I ran the given code It shows the following error.
      Invalid type 'Q' in unpack at pack.pl line 9.
      --$ugum@r--
        From perldoc -f pack:
        Q An unsigned quad value. (Quads are available only if your system supports 64-bit integer values _and_ if Perl has been compiled to support those. Causes a fatal error otherwise.)

        (($_="Mzz ojjdloobnf jt uvy5502383")=~y~b-zg2-5c96-81~a-z0-9~s)=~s~~~s; print

        You could also simply try

        my $x1 = $r << 32 | $t; printf "\nThe value is 0x%x", $x1; # 0x23400000345

        (though whether this works similarly depends of the build options of your perl)

        P.S.: What exactly do you need this for?  Maybe bigint or Math::BigInt would help.

        Update:

        use bigint; my $r = 0x234; my $t = 0x345; my $x1 = $r << 32 | $t; print $x1->as_hex;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://828246]
Approved by almut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (14)
As of 2014-12-29 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (188 votes), past polls