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

Need Raw Binary Output

by Anonymous Monk
on Dec 05, 2016 at 20:35 UTC ( [id://1177284]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm generating random 32 bit integers based on Math::Random::MTwist. I want to pipe the raw binary output, but (obviously) print() won't do. Neither will syswrite() to STDOUT.

Am I missing something simple?

Replies are listed 'Best First'.
Re: Need Raw Binary Output
by Anonymous Monk on Dec 05, 2016 at 21:01 UTC

    See pack:

    print pack('N',123456789); # unsigned, big-endian # output (hex): 07 5b cd 15 print pack('V',123456789); # unsigned, little-endian # output (hex): 15 cd 5b 07

      Yep! Looks like just what I needed. And simple, as I suspected (and hoped).

      Thank you for the help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1177284]
Approved by Paladin
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found