[squeak-dev] Two's Complement and Squeak Integers
karlramberg at gmail.com
Tue Jun 16 17:44:08 UTC 2020
Integer readFrom: '11111111' readStream base: 2. ?
On Tue, Jun 16, 2020 at 6:36 PM Eric Gade <eric.gade at gmail.com> wrote:
> 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...
More information about the Squeak-dev