Re: Manipulating binary data



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



Relevant Pages

  • Re: Useful class for binary data storate and manipulation
    ... > I'm trying to decide on a structure to store Message Data. ... > contains binary data of arbitrary format and length. ... > some sort of array of bytes containing whatever the message is. ... It has no functionality below the byte level, if you need to be able to set ...
    (comp.lang.java.help)
  • Re: Finding the nearest match without reusing results
    ... comparing an array with a value generates an array of Trues and ... Any diff with wrong State or with used Store is implicitly zeroed out. ... Each must be larger than the absolute value of the maximum Sales ... go.....it just needs to return the closest match. ...
    (microsoft.public.excel.programming)
  • Re: read keyboard input and storing in an array?
    ... > I'm trying to store user input in an array, ... You have the beginnings of that logic already since your prompt tells the ... 201st value since the array only has room for 200 values. ... This will force you to store the int values as Integer ('Integer' ...
    (comp.lang.java.help)
  • Re: Challenge: reading ascii data
    ... to store all the data before producing any output. ... would be bad practice in terms of memory consumption to use a standard ... So I use hashes to create a two-level "sparse array", ... Well the original problem definition was: ...
    (comp.lang.fortran)
  • Re: attempting an actual game...
    ... >>> and inflexible by the absurd decision to use a bit array for square ... as then one has 8 bits in which to store a color and a few flags ... Using a 2D int (or, ... > Change direction and you may eventually complete a game. ...
    (comp.games.development.programming.misc)