Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: String to Hex

by blazar (Canon)
on May 22, 2007 at 22:24 UTC ( #616892=note: print w/replies, xml ) Need Help??


in reply to Re: String to Hex
in thread String to Hex

Update: Unstruck on advice ;)

I also agree that it deserved being unstruck. But:

  • I would $num >>= 32;
  • AIUI from earlier posts by knowledgeable people, the technique is valid for numbers such that the loop will always involve one or at most two iterations of the loop.

Update: s/16/32/ applied above, thanks GF.

Replies are listed 'Best First'.
Re^3: String to Hex
by BrowserUk (Patriarch) on May 22, 2007 at 22:40 UTC
    I would $num >>= 16;

    Both methods have problems on 32-bit systems.

    GrandFather's produces the correct result and warnings, but yours gives the wrong result?

    print 24600988483 / 2**32;; 5.72786398301832 print 24600988483 / 0x100000000;; Integer overflow in hexadecimal number at (eval 24) line 1 Hexadecimal number > 0xffffffff non-portable at (eval 24) line 1 5.72786398301832 print 24600988483 >> 16;; 65535

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Warnings? With AS Perl 5.8.7 I see no warnings with either the code I posted or with the (corrected) $num >>= 32; variant suggested by blazar. You did use bigint; didn't you?


      DWIM is Perl's answer to Gödel
        You did use bigint; didn't you?

        Rhetorical I assume, but I'll answer it anyway. No. I missed that slightly significant detail :)

        Annoyingly, I did look for use Math::BigInt;, but completely missed the presence of the pragma variant!


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2022-01-18 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (52 votes). Check out past polls.

    Notices?