Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
go ahead... be a heretic
 
PerlMonks  

Re: Creating a binary file problem

by Eliya (Vicar)
on Apr 05, 2012 at 17:22 UTC ( #963718=note: print w/ replies, xml ) Need Help??


in reply to Creating a binary file problem

It's not entirely clear to me what exactly you want to be written to the file, but in case you want to print the values expressed in the hex strings (such as "0x0000001b") as binary values to the file, you could say

my $hex = "0x0000001b"; print BIN pack('H*', substr($hex,2));

This would also work for values larger than a Perl number could hold.  In the example above, it would write 4 bytes / 32 bits.

On a side note, don't use printf, unless you actually specify a format string.


Comment on Re: Creating a binary file problem
Select or Download Code
Re^2: Creating a binary file problem
by ikegami (Pope) on Apr 05, 2012 at 20:46 UTC
    Given his use of pack 'C', I imagine he wants the single byte 1B, so
    print BIN pack('C', hex($hex));

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-04-20 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls