By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,996 Members | 1,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,996 IT Pros & Developers. It's quick & easy.

arrays -- can they be words, not bytes?

P: n/a
I have an array whose elements I'm accessing, like array[0], array[1], etc.
However, the data is meant to be 16-bit words, not bytes. I'm getting byte
values right now. Is there
any way I can tell php that an array is composed of words and not bytes?

Thanks
B
Oct 17 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
In our last episode, <13*************@corp.supernews.com>, the lovely and
talented Bint broadcast on comp.lang.php:
I have an array whose elements I'm accessing, like array[0], array[1],
etc. However, the data is meant to be 16-bit words, not bytes. I'm
getting byte values right now. Is there any way I can tell php that an
array is composed of words and not bytes?
Your question appears to be nonsense. In PHP, arrays are a compound type.
The keys must be integers or strings (yours appear to be integers so far).
Values may be any PHP type including array. The maximum size of the types
are, in general, platform dependant, but I do not know of a platform on
which PHP will compile in which you would be limited to 8 bits. If you are
getting byte values out of an array it is because someone, possibly you, put
byte values into the array. If you want 16-bit values in an array, put
16-bit values in it.

PHP is a high-level language. Ordinarily you should not know or care what
the low-level memory arrangements are. If you are trying to do something
special, you'll have to tell us what it is.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 460 days to go.
What do you do when you're debranded?
Oct 17 '07 #2

P: n/a
"Bint" <bi**@csgs.comwrote in news:13*************@corp.supernews.com:
I have an array whose elements I'm accessing, like array[0], array[1],
etc. However, the data is meant to be 16-bit words, not bytes. I'm
getting byte values right now. Is there
any way I can tell php that an array is composed of words and not
bytes?
Hmm, I think you're a bit confused, or at least I am.

Put whatever you want in the array:

$storeAddress['Kamloops'] = "128 Harry Street";
$storeAddress['Toronto'] = "2555 Yonge Street";

And what is a 16-bit word?
Oct 17 '07 #3

P: n/a
Bint wrote:
I have an array whose elements I'm accessing, like array[0], array[1], etc.
However, the data is meant to be 16-bit words, not bytes. I'm getting byte
values right now. Is there
any way I can tell php that an array is composed of words and not bytes?

Thanks
B
Not really. PHP is not meant for low-level bit manipulation. And you
can't really control the size of the word - it can differ between 32 and
64 bit architectures, for instance.

What are you string in those words, anyway?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 17 '07 #4

P: n/a
Good Man wrote:
"Bint" <bi**@csgs.comwrote in news:13*************@corp.supernews.com:
>I have an array whose elements I'm accessing, like array[0], array[1],
etc. However, the data is meant to be 16-bit words, not bytes. I'm
getting byte values right now. Is there
any way I can tell php that an array is composed of words and not
bytes?

Hmm, I think you're a bit confused, or at least I am.

Put whatever you want in the array:

$storeAddress['Kamloops'] = "128 Harry Street";
$storeAddress['Toronto'] = "2555 Yonge Street";

And what is a 16-bit word?
Assembler term - two 8-bit bytes handled as one 16 bit word. And 4
bytes can be handled as a 32 bit DWORD.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 17 '07 #5

P: n/a
Yeah, I guess I'm trying to do something low-level with this high-level
lanugage. I'm new to PHP so I'm trying to figure out how these fancy
keyword-based arrays work with old-school byte arrays.

I'm sending images wirelessly to a php script. The image, originally a grid
of pixels, each 16-bits deep, is run-length-encoded into a smaller C array
of unsigned shorts (16 bit words). That C array is base64 encoded into an
ASCII string so that I can send it via HTTP POST command to a PHP script.

The PHP script sees my base64 encoded array as a variable, which I can
easily base64 decode into a php "array". But it is proving trickier to
access my pixel values, because now the array is not a C array, but a PHP
one. If I look at the value of array[0], then I don't get the number that
was in array[0] before I sent it.

I can work around it, by accessing each byte of the PHP array:

$myoriginalarray[0] = ord($phparray[0]) + ord($phparray[1]) << 8;

But that is complicated and I just thought there might be some simpler way
of telling PHP "hey, I have an array of unsigned shorts here".
Maybe not.

B


"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:D_******************************@comcast.com. ..
Bint wrote:
>I have an array whose elements I'm accessing, like array[0], array[1],
etc.
However, the data is meant to be 16-bit words, not bytes. I'm getting
byte values right now. Is there
any way I can tell php that an array is composed of words and not bytes?

Thanks
B

Not really. PHP is not meant for low-level bit manipulation. And you
can't really control the size of the word - it can differ between 32 and
64 bit architectures, for instance.

What are you string in those words, anyway?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 17 '07 #6

P: n/a
Bint wrote:
Yeah, I guess I'm trying to do something low-level with this high-level
lanugage. I'm new to PHP so I'm trying to figure out how these fancy
keyword-based arrays work with old-school byte arrays.

I'm sending images wirelessly to a php script. The image, originally a grid
of pixels, each 16-bits deep, is run-length-encoded into a smaller C array
of unsigned shorts (16 bit words). That C array is base64 encoded into an
ASCII string so that I can send it via HTTP POST command to a PHP script.

The PHP script sees my base64 encoded array as a variable, which I can
easily base64 decode into a php "array". But it is proving trickier to
access my pixel values, because now the array is not a C array, but a PHP
one. If I look at the value of array[0], then I don't get the number that
was in array[0] before I sent it.

I can work around it, by accessing each byte of the PHP array:

$myoriginalarray[0] = ord($phparray[0]) + ord($phparray[1]) << 8;

But that is complicated and I just thought there might be some simpler way
of telling PHP "hey, I have an array of unsigned shorts here".
Maybe not.

B


"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:D_******************************@comcast.com. ..
>Bint wrote:
>>I have an array whose elements I'm accessing, like array[0], array[1],
etc.
However, the data is meant to be 16-bit words, not bytes. I'm getting
byte values right now. Is there
any way I can tell php that an array is composed of words and not bytes?

Thanks
B
Not really. PHP is not meant for low-level bit manipulation. And you
can't really control the size of the word - it can differ between 32 and
64 bit architectures, for instance.

What are you string in those words, anyway?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


Nope, not really. But I think I'd do that processing in C anyway.
Either call it as an external module or write an extension to PHP for it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 17 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.