473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Pack yields unwanted bytes

Hello!

Maybe this question has already popped up somewhere, but I'm new to this
forum and there is apparently no way to search the past questions and
answers...
I have written a script that needs to produce binary files. I am using active perl
on windows.
I am using the function "pack" to get the bytes into the binary file.

So for instance pack("c", 0x41); results in getting the character "A" into
the file. However, if I do: pack("c", 10); , I think I should get 0x0A in my file
but instead it puts 2 bytes in the file, 0x0D, 0x0A.

Could anybody tell me how to enter exactly what I want and no extra bytes?

Here is a sample code:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. open(outfile, ">Test.bin");
  3. print outfile pack("C", 10);
  4. close(outfile);
  5.  
This works very well in MacOS-X, this does not work with ActivePerl, the
file produced has 2 bytes instead of one.

Thanks for any hint,

Pascal
Mar 10 '08 #1
0 923

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Stacy Mader | last post by:
Greetings all, I have a VMS binary file with weather data. The record on each line is 1xint(8) 12xint(2) Using the perl unpack function, I can decode the binary file like this: <snip>
8
by: Mike | last post by:
The following struct, DataStruct, is only part of a larger one that contains additional fields and arrays. I need the explicit layout because this struct is really a union, where some of the...
0
by: Shravan | last post by:
Hi, I have a extended datagrid, in which I am setting values at a given cell in the grid using grid = val; The grid has NewRow creation set to false But sometimes setting value at a...
1
by: Alex Stapleton | last post by:
from struct import pack >>> pack("B", 1) '\x01' >>> pack("BB", 0, 1) '\x00\x01' >>> pack("BI", 0, 1) '\x00\x00\x00\x00\x01\x00\x00\x00' >>> calcsize("BI") 8 >>> calcsize("BB")
18
by: p.lavarre | last post by:
Can Python not express the idea of a three-byte int? For instance, in the working example below, can we somehow collapse the three calls of struct.pack into one? 08 12 34 56 80 00 I ask...
1
by: dominik | last post by:
Hi, I am trying to pack an integer into 24bit value - 3 bytes, and write it to a file. I would like to know, if anyone knows if this is possible and how? Also, how to unpack that value back
8
by: active | last post by:
I have this and it seems to be working OK but now I wonder if the Pack value shouldn't be 1. What do you think? <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Auto)_ Public...
5
by: Steven Clark | last post by:
Can anyone explain to me why struct.pack('HB',1,2) gives 3 bytes, whereas struct.pack('BH',1,2) gives 4 bytes? -Steven
0
by: Cameron Simpson | last post by:
On 25Jun2008 22:38, Steven Clark <steven.p.clark@gmail.comwrote: | On Wed, Jun 25, 2008 at 7:03 PM, John Machin <sjmachin@lexicon.netwrote: | On Jun 26, 9:00 am, "Steven Clark"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.