<div dir="ltr"><div>Hi Karl,</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Integer readFrom: '<font face="monospace"><font face="arial,sans-serif"><font face="monospace">11111111</font></font></font>' readStream base: 2.  ?</div></blockquote><div><br></div><div>When I evaluate this in Squeak, the Integer produced is 255 (I need to get from 255 to -1 -- and back again if possible).</div><div>  <br></div><div>One hint that I've found in the image is that Integers respond to a message #highBitOfMagnitude, which gives me the value of the most significant bit in the integer. That is a starting point if I want to treat the bits in twos-complement: I can determine if the desired representation should be negative or positive. However, I'm not sure how to actually translate the bits into a matching Squeak integer with the correct sign and value.</div><div><br></div><div>Here is a more concrete explanation of my issue: In the implementation / simulation, Register objects store their values as Squeak Integers, and they are truncated at evaluation to be 32-bit integers. Some instructions will treat a register as signed and others as unsigned. For unsigned treatment, there's no problem: Squeak always has the correct bit values for what I need. I just need to figure out what to "do" with the integer in the register when I want to treat it as signed. In the case of a value like -1 ('11111111') I can send that #highBitOfMagnitude to determine if it should be a negative or positive value, but then what? I can't just send #negative, because that gives me -255</div><div><br></div><div>PS - Perhaps at some point there was a #twosComplement method implemented on Integers. There is an EToys object that is currently sending the message (which has no implementors in 5.3 as far as I can see): SecurityManager >> #asn1Integer:</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 16, 2020 at 1:44 PM karl ramberg <<a href="mailto:karlramberg@gmail.com" target="_blank">karlramberg@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Integer readFrom: '<font face="monospace"><font face="arial,sans-serif"><font face="monospace">11111111</font></font></font>' readStream base: 2.  ?</div><div><br></div><div>Best,</div><div>Karl<br></div><div><br></div><div><br></div></div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 16, 2020 at 6:36 PM Eric Gade <<a href="mailto:eric.gade@gmail.com" target="_blank">eric.gade@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi everyone,</div><div><br></div><div>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.</div><div><br></div><div>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).</div><div><br></div><div>For example, doing the following:</div><div style="margin-left:40px"><font face="monospace">-1 printStringBase: 2 nDigits: 8. "11111111"</font></div><div><font face="monospace"><font face="arial,sans-serif">Gives the expected binary value "11111111"</font></font></div><div><font face="monospace"><font face="arial,sans-serif"><br></font></font></div><div><font face="monospace"><font face="arial,sans-serif">However (and as we should expect), evaluating the following:</font></font></div><div style="margin-left:40px"><font face="monospace"><font face="arial,sans-serif"><font face="monospace">2r11111111. "255"</font></font></font></div><div style="margin-left:40px"><font face="monospace"><font face="arial,sans-serif"><font face="monospace"><br></font></font></font></div><div><font face="monospace"><font face="arial,sans-serif">Gives the (again, expected) value 255.</font></font></div><div><font face="monospace"><font face="arial,sans-serif"><br></font></font></div><div><font face="monospace"><font face="arial,sans-serif">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.</font></font></div><div><font face="monospace"><font face="arial,sans-serif"><br></font></font></div><div><font face="monospace"><font face="arial,sans-serif">Thanks!<br></font></font></div><div><div><div><div><div><br>-- <br><div dir="ltr"><div dir="ltr"><div>Eric</div></div></div></div></div></div></div></div></div>
<br>
</blockquote></div>
<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr"><div dir="ltr"><div>Eric</div></div></div>