[Newbies] Storing a negative SmallInterger in a ByteArray
Lukas Renggli
renggli at gmail.com
Mon Mar 5 10:48:13 UTC 2007
> I am a bit confused...
> I am working on an implementation to communicate with the Lego
> Mindstorms NXT. Al works fine, except I have to store some negative
> numbers in the ByteArray that should be send to the NXT. Everytime I
> try, I get an improper store into indexable object.
The elements of a ByteArray are unsigned bytes, a value between 0 and 255.
> Is it possible to store negative values in a ByteArray?
There are several helper methods implemented in ByteArray. Have a look
at the code I sent you, the NxtConnection>>#send: primitive makes use
of these methods:
doubleAt: index put: value bigEndian: bool
longAt: index put: value bigEndian: aBool
shortAt: index put: value bigEndian: aBool
unsignedLongAt: index put: value bigEndian: aBool
unsignedShortAt: index put: value bigEndian: aBool
Cheers,
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch
More information about the Beginners
mailing list