arrays -- can they be words, not bytes?

arrays -- can they be words, not bytes?

am 17.10.2007 21:22:09 von grande news

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

Re: arrays -- can they be words, not bytes?

am 17.10.2007 21:52:54 von Lars Eighner

In our last episode, <13hco71gbsmmb66@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
Countdown: 460 days to go.
What do you do when you're debranded?

Re: arrays -- can they be words, not bytes?

am 17.10.2007 21:53:08 von Good Man

"Bint" wrote in news:13hco71gbsmmb66@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?

Re: arrays -- can they be words, not bytes?

am 17.10.2007 22:13:04 von Jerry Stuckle

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.
jstucklex@attglobal.net
==================

Re: arrays -- can they be words, not bytes?

am 17.10.2007 22:13:51 von Jerry Stuckle

Good Man wrote:
> "Bint" wrote in news:13hco71gbsmmb66@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.
jstucklex@attglobal.net
==================

Re: arrays -- can they be words, not bytes?

am 17.10.2007 22:25:01 von grande news

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" wrote in message
news:D_SdneeS0bxw8YvanZ2dnUVZ_qHinZ2d@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.
> jstucklex@attglobal.net
> ==================
>

Re: arrays -- can they be words, not bytes?

am 17.10.2007 22:48:59 von Jerry Stuckle

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" wrote in message
> news:D_SdneeS0bxw8YvanZ2dnUVZ_qHinZ2d@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.
>> jstucklex@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.
jstucklex@attglobal.net
==================

Re: arrays -- can they be words, not bytes?

am 17.10.2007 23:08:35 von Lars Eighner

In our last episode,
<13hcrsv3c5a2584@corp.supernews.com>,
the lovely and talented Bint
broadcast on comp.lang.php:

> 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.

Treat them as a string, use the base 64 decode function which takes a string
argument and returns a string result. In many respects strings are a kind
of array, but they are not type array in PHP. Conveniently, strings are
composed of characters, and characters bear more than a passing resemblance
to 8-bit unsigned integers. Take them two at time if you have to manipulate
them at the 16-bit level. See chapter 11 (Types) in the manual for hints as
to how to work with strings. Don't use curly brackets, they will be
deprecated in PHP 6, or so the scuttlebutt goes.

Do not be confused by PHP array type. Although strings are kind of like
arrays with integer indices, there are significant differences. You should
be learning to use strings from the documentation on type string, and the
documentation on type array is likely to mislead you.


--
Lars Eighner
Countdown: 460 days to go.
What do you do when you're debranded?

Re: arrays -- can they be words, not bytes?

am 17.10.2007 23:33:26 von grande news

Well, let me ask you. I've got the code working now, using the method I
described above. But just for my edification, how do I know if I am working
with strings or arrays?

The thing begins as a POST incoming variable, say $image.
Then if I start accessing elements of it, ie $image[0], $image[1], etc, then
am I accessing string elements?
And if I make a *new* entity, say $output, and start saying things like
$output[0] = ord($image[0]) + (ord($image[1])<<8), then am I creating a
string there, or an array?

Thanks
B



"Lars Eighner" wrote in message
news:slrnfhcucm.157i.usenet@debranded.larseighner.com...
> In our last episode,
> <13hcrsv3c5a2584@corp.supernews.com>,
> the lovely and talented Bint
> broadcast on comp.lang.php:
>
>> 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.
>
> Treat them as a string, use the base 64 decode function which takes a
> string
> argument and returns a string result. In many respects strings are a kind
> of array, but they are not type array in PHP. Conveniently, strings are
> composed of characters, and characters bear more than a passing
> resemblance
> to 8-bit unsigned integers. Take them two at time if you have to
> manipulate
> them at the 16-bit level. See chapter 11 (Types) in the manual for hints
> as
> to how to work with strings. Don't use curly brackets, they will be
> deprecated in PHP 6, or so the scuttlebutt goes.
>
> Do not be confused by PHP array type. Although strings are kind of like
> arrays with integer indices, there are significant differences. You
> should
> be learning to use strings from the documentation on type string, and the
> documentation on type array is likely to mislead you.
>
>
> --
> Lars Eighner
>
> Countdown: 460 days to go.
> What do you do when you're debranded?

Re: arrays -- can they be words, not bytes?

am 17.10.2007 23:42:25 von unknown

Post removed (X-No-Archive: yes)

Re: arrays -- can they be words, not bytes?

am 17.10.2007 23:55:20 von Lars Eighner

In our last episode, <13hcvt7td63bhcd@corp.supernews.com>, the lovely and
talented Bint broadcast on comp.lang.php:

> Well, let me ask you. I've got the code working now, using the method I
> described above. But just for my edification, how do I know if I am working
> with strings or arrays?

> The thing begins as a POST incoming variable, say $image.
> Then if I start accessing elements of it, ie $image[0], $image[1], etc, then
> am I accessing string elements?
> And if I make a *new* entity, say $output, and start saying things like
> $output[0] = ord($image[0]) + (ord($image[1])<<8), then am I creating a
> string there, or an array?

You are creating an array. ord returns an integer.

--
Lars Eighner
Countdown: 460 days to go.
What do you do when you're debranded?