On 10/8/07, Tracy Harms <[EMAIL PROTECTED]> wrote:
> > If not ordinals or codes, use a k-column literal
> > matrix where k e. 1 2 4 to encode k-byte integers,
> > and convert each time you need the numbers.
>
> I would like to be able to study a wiki essay on this
> technique. If writing such an essay is a pleasant
> endeavor for anybody, I'm confident it will be
> appreciated widely.
Here's one approach:
k2=: (&.(256 256#.a.i.]))("1)
a=:2 2$'abcd'
b=:2 2$'defg'
a.i.L:0 a;b;a +k2 b
+------+-------+-------+
|97 98|100 101|197 199|
|99 100|102 103|201 203|
+------+-------+-------+
This treatment represents unsigned 16 bit integers (and optimizes
for space at the expense of time).
rep2=: (&(256 256#.a.i.]))("1)
":rep2 L:0 a;b;a +k2 b
+-----+-----+-----+
|24930|25701|50631|
|25444|26215|51659|
+-----+-----+-----+
Note also that both k2 and rep2 assume they will be used
with scalar verbs. You could rephrase things to remove that
assumption. For example:
K2=: &.:((256 256#.a.i.])"1)
but this tries to convert the entire array at once, which may
be counter-productive in some circumstances (because of
the space required).
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm