Byte order and ByteArray conversions

John.Maloney at disney.com John.Maloney at disney.com
Mon Nov 1 19:33:54 UTC 1999


David:

The way to do this is to leverage off the fact that BitBlt
can copy into either a ByteArray or a Bitmap object. (See
the method "hackBits:".) What you do is to make a one-word
Form with a byte array as its bits, then set the first
byte to, say, 1. You BitBlt it into another one-word Form
with a real Bitmap as its bits and read out the word using
"bits at: 1". You'll either get 1 or 2^24, depending on the
native byte ordering of the underlying architecture.

Warning: BitBlt may soon change so that this trick no longer
works. But there will probably be a similar trick that you
can use.

Hope this helps.

	-- John


is pretty easy to do if you realize
that
>I'm sure I'm missing something obvious, but I'd like to be able to convert
>integers to and from byte arrays in native machine byte ordering, without
>resorting to a new primitive.
>
>1) Does Squeak know the byte order convention of the hardware it's running
>on? I can't find any method to query for this.
>
>2) Class ByteArray knows how to convert itself into integers, given that
>you can tell it the answer to question 1.  Is there any existing method
>for converting an integer into a four byte array?
>
>Thanks.





More information about the Squeak-dev mailing list