Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing an integer to a file

Status
Not open for further replies.

endfx

Technical User
Jun 14, 2006
6
0
0
CA
I have a variable that holds a number:

my $num = 0;

I want to write that number to a file such that 0 (NULL) shows up in the file rather than it's ascii value (0x30 or 48) ... I'm making a binary file, not a text file.

I've tried the following:

open FILE, ">", "test.bin"
printf FILE "%c", $num
printf FILE "%u", $num
printf FILE "%x", $num

But it always shows up as the ascii rather than the actual value.

Can anyone help me?
I would also like to know that this number will always be less than 256, so the value it writes has to go into 1 byte.
Can't use up 4 bytes or anything like that.

Thanks for looking.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top