Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 1998-11-24
Medium Priority
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
Question by:djc2
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 84

Expert Comment

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

Author Comment

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?
LVL 84

Expert Comment

ID: 1206559
What grade do you want to give?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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?
LVL 84

Accepted Solution

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

Author Comment

ID: 1206562
OK, thanks.
LVL 84

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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

610 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