Improve company productivity with a Business Account.Sign Up

x
?
Solved

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

Posted on 1998-11-24
7
Medium Priority
?
227 Views
Last Modified: 2010-03-04
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
0
Comment
Question by:djc2
  • 4
  • 3
7 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 1206557
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
0
 

Author Comment

by:djc2
ID: 1206558
OK that works ... I guess it wasn't as difficult a question as I thought. Thanks. So how do I give you a grade?
0
 
LVL 85

Expert Comment

by:ozo
ID: 1206559
What grade do you want to give?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 

Author Comment

by:djc2
ID: 1206560
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?
0
 
LVL 85

Accepted Solution

by:
ozo earned 1200 total points
ID: 1206561
The system hasn't changed.  I just wanted to be sure you got everything you needed before locking the question
0
 

Author Comment

by:djc2
ID: 1206562
OK, thanks.
0
 
LVL 85

Expert Comment

by:ozo
ID: 1206563
You're welcome.
perldoc -f pack
should tell you about other pack/unpack formats that may be useful
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

584 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question