Re: Manipulating binary data
- From: Toby A Inkster <usenet200703@xxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 11:49:47 +0100
brainflakes.org wrote:
Are there actually any proper binary extensions or is using gd lib the
way to go (as I guess it's just dealing with binary data as a 2d array
anyway)
Assuming that each "row" of data is of the same length, and each "column"
has the same height (which I think is a fairly safe assumption if you're
modelling the data as a rectangular image) then, why not just store the
data as a string. That is, instead of storing a 3x3 array of data as this:
$array = array(
array(0x61, 0x62, 0x63),
array(0x31, 0x32, 0x33),
array(0x78, 0x79, 0x7A)
);
you store it as:
$string = 'abc123xyz';
Which is roughly how a 2-dimensional array is internally stored by a C
program.
Instead of this:
$cell = $array[$x][$y];
You use:
define(ROW_LENGTH, 3);
$cell = $string[(ROW_LENGTH*$x) + $y];
And instead of this:
$array[$x][$y] = 0x64;
this:
$string[(ROW_LENGTH*$x) + $y] = chr(0x64);
--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
.
- Follow-Ups:
- Re: Manipulating binary data
- From: Chung Leong
- Re: Manipulating binary data
- From: brainflakes . org
- Re: Manipulating binary data
- References:
- Manipulating binary data
- From: brainflakes . org
- Manipulating binary data
- Prev by Date: Re: Select statement with a NULL
- Next by Date: Re: Manipulating binary data
- Previous by thread: Re: Manipulating binary data
- Next by thread: Re: Manipulating binary data
- Index(es):
Relevant Pages
|