473,406 Members | 2,867 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,406 software developers and data experts.

pack format - how do I handle int->char conversion?

I am trying to pack a string. The data consists of an array of
integers, something like this:

e[1] 0x1234
e[2] 0x0001
e[3] 0x0002

What I want in my resulting packed $binrow is

0x1234 0x01 0x02

I've tried

pack("nCC",e[1],e[2],e[3])

but that packs it like this:

0x1234 0x00 0x31 0x00 0x32

which is most definitely not what I want.

How can I explicitly tell PHP that I want to cast an int as a char?

(Sorry if this is a FAQ somewhere, but I can't find it... This is
trivial to my C-trained mind but I can't see how to do it in PHP.)

--Yan
Dec 8 '06 #1
1 1717
CptDondo wrote:
How can I explicitly tell PHP that I want to cast an int as a char?
Never mind, stupid bonehead error in the code.

--Yan
Dec 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bruce Cushman | last post by:
My DB is Access 2000 based "possibly written in 2002" and I have to send and receive update files, ported to a UNIX server by FTP, DB unknown. The file content uses a fixed length string, zero...
22
by: bvb | last post by:
Hi, while declaring/defining pointer to int/char, What is doing the compiler exactly . i'm able to get output(String) for all pointer to char definition(without line # 8&14). But when i include...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
23
by: Matt Garman | last post by:
Is there a clean, portable way to determine the maximum value of converted numerical fields with printf()-like functions? Doing this at compile-time would be preferable. For example, %i should...
5
by: Richard Thrasher | last post by:
Writing my very first C# program, I found what appears to be a compiler error. The statement int temp = (int)(100 * 36.41); assigns the value 3640 to temp. I've tried this code with various...
8
by: Shawn B. | last post by:
Greetings, Me again. I have (roughly) the following code: HANDLE hConsoleOutput; HANDLE hConsoleInput;
15
by: k3n3dy | last post by:
Hello everybody, I would like to ask anybody to help me understand what should be done exactly with this Problem. I have provided what I have up to now, although it is not quite accurate. Create...
3
by: martin paul | last post by:
Sir please consider the following code.I've tried the following code to print whether the MSB of a int/char is zero or one. int main () { unsigned char ch; int...
4
by: aki | last post by:
i am receiving a packet from network and it contains many fields , starting from code, idetifier ...., i want to read the code field which is of size 1 byte. checking the code value i need to go...
1
by: Rizvi | last post by:
I can not find any details about video conversion algorithm.. how video is converted to one format to another format...?what is the algorithm? I want to know the mechanism.. where can i get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.