[squeak-dev] Two's Complement and Squeak Integers

Eric Gade eric.gade at gmail.com
Tue Jun 16 16:35:51 UTC 2020

Hi everyone,

I'm smack in the middle of making some RISC-V tools in Squeak, which means
I'm dealing with a lot of low-level bit manipulation.

One question I have is how best to deal with two's complement
representations of integers in Squeak, and how to translate between the
different (positive v negative) values based on a given set of bits (or a
byteArray or whatever).

For example, doing the following:
-1 printStringBase: 2 nDigits: 8. "11111111"
Gives the expected binary value "11111111"

However (and as we should expect), evaluating the following:
2r11111111. "255"

Gives the (again, expected) value 255.

My question is: what is the best way to convert between the complements in
Squeak? How can I take 255, examine its bits, and get -1 as the response
(or convert in the reverse)? I'm assuming there are already ways to deal
with this, I just cannot find them.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200616/5bfb9751/attachment.html>

More information about the Squeak-dev mailing list