Solved

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

Posted on 1998-11-24
7
206 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 84

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 84

Expert Comment

by:ozo
ID: 1206559
What grade do you want to give?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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 84

Accepted Solution

by:
ozo earned 300 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 84

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

840 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