Link to home
Start Free TrialLog in
Avatar of djc2
djc2

asked on

can I output integer data in binary form rather than ASCII?

I am processing some data with perl. I need to output my integer data in 2-byte signed (i.e., -32768 to +32768) binary format rather than standard ascii text format. [i.e., analogous to outputing data with the write() C-language command available from unistd.h]. I don't want to have any end-of-line characters between each integer value. Is there a way to do this in perl?
Thanks, Dave
Avatar of ozo
ozo
Flag of United States of America image

pack('s',32768) #a signed short value
pack('n',32768) #a short in "network" (big-endian) order
pack('v',32768) #a short in "VAX" (little endian) order
Avatar of djc2
djc2

ASKER

OK that works ... I guess it wasn't as difficult a question as I thought. Thanks. So how do I give you a grade?
What grade do you want to give?
Avatar of djc2

ASKER

So whether or not you tell me how to give you a grade depends on what the grade is, huh? (just kidding) ... A

In the past I thought that I was always given the option to give a grade. Has the system changed?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of djc2

ASKER

OK, thanks.
You're welcome.
perldoc -f pack
should tell you about other pack/unpack formats that may be useful