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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write in binary

Status
Not open for further replies.

zhang1129

Programmer
Joined
Jan 24, 2006
Messages
3
Location
US
Hi, All.
I am trying to write some data into a binary file

--------------------------------------
open (FH, ">c.dat" || die "$!");
binmode (FH);
print FH "123.3456";
---------------------------------------
the result I got in c.dat is 123.3456.

but i really want the result in unicode( the strange characters, like in exe files).

any body can help me with this?

thanks first.

kevin
 
thanks.
aacturally I used pack/unpack for this porblem, but the result is binary string:

like
-----------------------
sub dec2bin{
my $str = unpack("B*", pack("f", shift));
$str =~ s/^0+(?=\d)//;
return $str;
}
open (FH, ">c.dat" || die "$!");
binmode (FH);
print FH dec2bin(123.456);
----------------------------
but the result will be 1111011.

if I use:
print FH "\123";
the output will "S". this format is what i wanted.
but if I use print FH "\123.456";
the output will be "S.456".
part after dot is not converted to binary.....
how to solve this problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top