Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by Limbic~Region (Chancellor)
on Sep 07, 2016 at 20:54 UTC ( #1171334=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^9: Equivalent of unpack 'q' with 32-bit Perl (a8)
by RonW (Vicar) on Sep 08, 2016 at 16:34 UTC

    This seems to do what you are asking:

    #!perl use strict; use warnings; use Digest::MD5 qw(md5 md5_hex); use Math::BigInt; my $foo = 'hello, world!'; my @v = unpack('q', md5($foo)); printf "%x %x\n", @v; my $h = substr(md5_hex($foo),0,16); # get first 8 bytes (pairs of hex +digits) my @w = reverse $h =~ /(..)/g; # split out the bytes and reverse +the order my $w = join('', @w); my $q = Math::BigInt->from_hex($w); print $q->as_hex();

    I was surprised that it was necessary to reverse the bytes to get the same result as unpack('q', md5($foo)) but that's what it took.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1171334]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2018-06-23 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (125 votes). Check out past polls.

    Notices?