Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^5: Equivalent of unpack 'q' with 32-bit Perl (a8)

by Anonymous Monk
on Sep 06, 2016 at 23:41 UTC ( [id://1171281]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Equivalent of unpack 'q' with 32-bit Perl (a8)
in thread Equivalent of unpack 'q' with 32-bit Perl

well, shouldn't need to involve vec at all, just use md5_hex to get hex version of digest ... you could unpack 'H*' ... and give that to bigint hex ...

also negatives, yeah I've no idea :)

  • Comment on Re^5: Equivalent of unpack 'q' with 32-bit Perl (a8)

Replies are listed 'Best First'.
Re^6: Equivalent of unpack 'q' with 32-bit Perl (a8)
by Limbic~Region (Chancellor) on Sep 06, 2016 at 23:51 UTC
    Anonymous Monk,
    just use md5_hex to get hex version of digest

    That's a brilliant (obvious) idea. I wish I had thought of it before I wrote the code above (which now handles negative numbers as well). I assume your approach will work but I am not inclined to verify (the guy I am helping should be able to do it himself). Thanks!

    Edit: After thinking about it for a minute, I don't think that would work. Basically, you have an 128 bit integer in binary form and you are then converting the first 64 bits of it into decimal form. I'm pretty sure a hex digest isn't going to help here because you can't simply just cut it in half.

    Cheers - L~R

      After thinking about it for a minute, I don't think that would work. Basically, you have an 128 bit integer in binary form and you are then converting the first 64 bits of it into decimal form. I'm pretty sure a hex digest isn't going to help here because you can't simply just cut it in half.

      That seems to be what unpack('q', md5($foo)) is doing - cutting the digest in half.

      use Digest::MD5 'md5'; my $foo = 'hello, world!'; my @v = unpack('q', md5($foo)); printf "%x %x\n", @v;
      $ perl unpackq.pl e3ba1f79d1badb3a 0

      If you really need to convert the whole digest to an integer, try Math::BigInt->from_hex(md5_hex($foo))

        RonW,

        If you really need to convert the whole digest to an integer

        I just need to duplicate the result of unpack('q', md5($thing)) on 32bit Perl. I wrote something that works at home (see this thread) but it doesn't seem to work at work and I can't understand why.

        Cheers - L~R

      Edit: After thinking about it for a minute, I don't think that would work. Basically, you have an 128 bit integer in binary form and you are then converting the first 64 bits of it into decimal form. I'm pretty sure a hex digest isn't going to help here because you can't simply just cut it in half.

      What are you talking about?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1171281]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-05-22 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found