[Vm-beginners] Converting between Word and Byte Array

Bert Freudenberg bert at freudenbergs.de
Wed Jul 11 10:07:49 UTC 2012


On 11.07.2012, at 11:39, Lars wrote:

> Hello,
> I'm at the moment working with ARM code, and the most convenient way to create memory chunks with instructions is word wise, by creating WordArray instances.
> But for some primitives, it would be better to have ByteArrays, because all pointers are byte-offsets. So borders have to be multiplied by 4, etc. Is there a convenient way to create one from the other?
> The 'asByteArray' or 'ByteArray newFrom:' both don't do the job.

Yes there is, in class Bitmap. A Bitmap is just a WordArray, but it provides conversion to/from ByteArrays:

| bitmap bytes words |
bitmap := Bitmap with: 16r80402010.
bytes := bitmap asByteArray.
words := (Bitmap new: bytes size // 4) copyFromByteArray: bytes.
bytes -> words first hex

- Bert -




More information about the VM-beginners mailing list