Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: sprintf %X endianness

by Anonymous Monk
on May 14, 2013 at 19:58 UTC ( #1033541=note: print w/ replies, xml ) Need Help??


in reply to Re: sprintf %X endianness
in thread sprintf %X endianness

and from that point on you need not consider the endianess . just use it and the code will do the right thing.

Did I mention I'm after 00204110 ? Does above sprintf return 00204110 on non-win32 machines?


Comment on Re^2: sprintf %X endianness
Re^3: sprintf %X endianness
by SuicideJunkie (Priest) on May 14, 2013 at 21:06 UTC

    Is your machine not big or little endian? That's pretty rare hardware.

    You can ask for the values in network order, or worst case, you can unpack it by bytes, and shuffle them manually.

      Is your machine not big or little endian? That's pretty rare hardware. You can ask for the values in network order, or worst case, you can unpack it by bytes, and shuffle them manually.

      heh, you mean like I did there with three unpack calls? My question is about how sprintf is supposed to work

Reaped: Please reap
by NodeReaper (Curate) on May 14, 2013 at 21:45 UTC
Re^3: sprintf %X endianness
by BrowserUk (Pope) on May 14, 2013 at 21:50 UTC
    Does above sprintf return 00204110 on non-win32 machines?

    No. Because your raw input isn't 00204110 as either big-endian or little-endian:

    $raw = "\1\24\2\0";; $local = unpack 'L>', $raw;; printf "%08x\n", $local;; 01140200 $local = unpack 'L<', $raw;; printf "%08x\n", $local;; 00021401

    I don't know of any machine that would represent that hex value with your input bit pattern.

    In fact, I would say it was impossible, because it would mean that the nybbles of the 3rd byte (and only the 3rd byte) would be reversed; and no machine does that!


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.

      No. Because your raw input isn't 00204110 as either big-endian or little-endian:

      *sigh* look at the op, 00021401 is the thing

        *sigh* look at the op, 00021401 is the thing

        *sign* Is what "thing"?

        Cos in the OP you wrote:"00021401", but in this post you wrote: 00204110 twice. Which should I take as being your requirement?

        IF you are now saying that the OP is what you want, then apply yourself, because what I posted in my first response is all you need:

        $raw = "\1\24\2\0";; $local = unpack 'L>', $raw;; printf "%08x\n", $local;; 01140200 $local = unpack 'L<', $raw;; printf "%08x\n", $local;; 00021401

        And yes, that last pair of statements will work regardless of the platform it is run on.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        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
Node Status?
node history
Node Type: note [id://1033541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2014-12-26 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (171 votes), past polls