Solved

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

Posted on 1998-11-24
7
171 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
Comment Utility
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
Comment Utility
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
Comment Utility
What grade do you want to give?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:djc2
Comment Utility
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
Comment Utility
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
Comment Utility
OK, thanks.
0
 
LVL 84

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now