Solved

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

Posted on 1998-11-24
7
195 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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