Hi all,

I would like to write binary values to disk (as well as read them) but don't
know how to do it.  In C-speak, something like this:

unsigned int foo = 42;
fwrite (&foo, sizeof (unsigned int), 1, stdout);

I think the answer involves something with pack and unpack, but I'm
completely lost as I have no experience with either.  The closest I got was

my $decimal_number = 42;
my $binary_number = unpack("B32", pack("N", $decimal_number));
print "Decimal number " . $decimal_number . " is " . $binary_number .
" in binary.\n\n";

which I've taken from
http://www.linuxconfig.org/Perl_Programming_Tutorial.  This doesn't
work since it's printing the number "42" in text binary; but
I think it is close...  Or I might be barking up the wrong tree and I should
be thinking about "fprintf" somehow...

Does anyone have any ideas?  Thank you!

Ray

Reply via email to