writing uint16's to a binary file

Ned Konz ned at bike-nomad.com
Tue Mar 12 19:11:42 UTC 2002


On Tuesday 12 March 2002 10:49 am, Ken Brown wrote:
> When I index into the ByteArray at 2, I'm having trouble understanding what
> it means exactly.

ByteArrays hold bytes, and are indexed starting at 1.

so:

b _ ByteArray new: 4.
b at: 2 put: 1.
 	a ByteArray(0 1 0 0)

Simple.

However, there are also some methods in there for storing bigger things than 
bytes -- on arbitrary byte boundaries.

so:

b _ ByteArray new: 8.
b unsignedShortAt: 2 put: 16r0102 bigEndian: true.
b 
	a ByteArray(0 1 2 0 0 0 0 0)

b _ ByteArray new: 8.
b unsignedShortAt: 2 put: 16r0102 bigEndian: false.
b a ByteArray(0 2 1 0 0 0 0 0)

The "2" in the above is a _byte_ index into the array; we're storing a 2-byte 
thing there.

-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com



More information about the Squeak-dev mailing list