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

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.

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2018-05-24 06:30 GMT
Find Nodes?
    Voting Booth?