<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>I want a 32bit signed value expressed in base 16 where e.g. 16_FFFFFFFF is equivalent to -1.<br><br> - Jay<br><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">From: hosking@cs.purdue.edu<br>Date: Thu, 11 Apr 2013 16:03:02 +1000<br>To: jay.krell@cornell.edu<br>CC: m3devel@elegosoft.com<br>Subject: Re: [M3devel] 32bit negative base 16 constants?<br><br><br>
Actually, writing that you get what you expressed:<div><br></div><div><span style="font-family:Times;">If an explicit base is present, the value of the literal must be less than </span><tt>2^Word.Size</tt><span style="font-family:Times;">, and its interpretation uses the convention of the </span><a href="http://www.cs.purdue.edu/homes/hosking/m3/reference/word-intf.html" style="font-family:Times;" target="_blank"><tt>Word</tt></a><span style="font-family:Times;"> interface.</span><br><br><div><div>Word.T is unsigned, so you only get the 32 bits you asked for.</div><div><br></div><div>If you want a signed value then you need to express the sign explicitly starting from a constant, just as you have done with:</div><div><br></div><div><blockquote><div class="ecxhmmessage" style="font-size:12pt;font-family:Calibri;"><div dir="ltr">CONST UID_WORD = (* 16_97E237E2 *) -1881139893;<br></div></div></blockquote></div><div><br></div><div>On Apr 11, 2013, at 3:14 PM, Jay K <<a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a>> wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div class="ecxhmmessage" style="font-size:12pt;font-family:Calibri;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;"><div dir="ltr"> <span class="ecxApple-converted-space"> </span><br> I have some 32bit constants. <span class="ecxApple-converted-space"> </span><br> <span class="ecxApple-converted-space"> </span><br>e.g.: <span class="ecxApple-converted-space"> </span><br> <span class="ecxApple-converted-space"> </span><br> CONST UID_WORD = 16_97E237E2; <span class="ecxApple-converted-space"> </span><br> <span class="ecxApple-converted-space"> </span><br> but this isn't right.<span class="ecxApple-converted-space"> </span><br> On a 64bit system, that is a 64bit integer<span class="ecxApple-converted-space"> </span><br> with a "large" positive value, instead of<span class="ecxApple-converted-space"> </span><br> the intended 32bit negative value.<span class="ecxApple-converted-space"> </span><br> <span class="ecxApple-converted-space"> </span><br> Is there an ideal (i.e. CONST) way to do this?<span class="ecxApple-converted-space"> </span><br> Portably to 64bit systems?<span class="ecxApple-converted-space"> </span><br> <span class="ecxApple-converted-space"> </span><br> I have found two unsatisfactory choices:<span class="ecxApple-converted-space"> </span><br> <span class="ecxApple-converted-space"> </span><br> 1) use decimal:<span class="ecxApple-converted-space"> </span><br> <span class="ecxApple-converted-space"> </span><br> #include <stdio.h><span class="ecxApple-converted-space"> </span><br> int main()<span class="ecxApple-converted-space"> </span><br> {<span class="ecxApple-converted-space"> </span><br> printf("%X %d\n", 0x97E237E2);<span class="ecxApple-converted-space"> </span><br> return 0;<span class="ecxApple-converted-space"> </span><br> }<span class="ecxApple-converted-space"> </span><br> <br> <br> cc 1.c<span class="ecxApple-converted-space"> </span><br> ./a.out<span class="ecxApple-converted-space"> </span><br>97E237E2 -1881139893<br><br>CONST UID_WORD = (* 16_97E237E2 *) -1881139893;<br> <br> <br> 2) change it to VAR and a runtime conversion:<br> <br> <br> PROCEDURE SignExtend(a, b: INTEGER): INTEGER =<br> BEGIN<br> b := Word.LeftShift(-1, b - 1);<span class="ecxApple-converted-space"> </span><br> IF Word.And(a, b) # 0 THEN<span class="ecxApple-converted-space"> </span><br> a := Word.Or(a, b);<span class="ecxApple-converted-space"> </span><br> END;<span class="ecxApple-converted-space"> </span><br> RETURN a;<span class="ecxApple-converted-space"> </span><br> END SignExtend;<span class="ecxApple-converted-space"> </span><br><br> PROCEDURE SignExtend32(a: INTEGER): INT32 =<span class="ecxApple-converted-space"> </span><br> BEGIN<span class="ecxApple-converted-space"> </span><br> RETURN SignExtend(a, 32);<span class="ecxApple-converted-space"> </span><br> END SignExtend32;<span class="ecxApple-converted-space"> </span><br><br> CONST IntegerToTypeid = SignExtend32;<span class="ecxApple-converted-space"> </span><br><br><br> VAR UID_WORD := IntegerToTypeid(16_97E237E2); (* CARDINAL *)<span class="ecxApple-converted-space"> </span><br><br>This gives a warning:<br><br>CONST UID_INTEGER : INT32 = 16_195C2A74; (* INTEGER *)<br><br>and then at runtime gives an error assigning it to an INT32.<br><br><br> any other ways?<span class="ecxApple-converted-space"> </span><br><br><br>Thanks,<br> - Jay<br><br><br></div></div></blockquote></div><br></div><br><br><div>
<span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;font-size:medium;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;"><div style="word-wrap:break-word;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><div style="word-wrap:break-word;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><div><font class="ecxApple-style-span" color="#0000FF"><font class="ecxApple-style-span" face="Gill Sans"><span class="ecxApple-style-span" style="color:rgb(0, 0, 255);font-family:'Gill Sans';"><span class="ecxApple-style-span" style="color:rgb(0, 0, 255);font-family:'Gill Sans';">Antony Hosking</span></span></font></font><font class="ecxApple-style-span" face="Gill Sans"><span class="ecxApple-style-span" style="font-family:'Gill Sans';"><span class="ecxApple-style-span" style="font-family:'Gill Sans';"><span class="ecxApple-converted-space"> </span>|<span class="ecxApple-converted-space"> </span></span></span><span class="ecxApple-style-span" style="font-family:'Gill Sans';"><span class="ecxApple-style-span" style="font-family:'Gill Sans';">Associate Professor</span></span><span class="ecxApple-style-span" style="font-family:'Gill Sans';"><span class="ecxApple-style-span" style="font-family:'Gill Sans';"> | Computer Science | Purdue University</span></span></font></div><div><font class="ecxApple-style-span" face="GillSans-Light"><span class="ecxApple-style-span" style="font-family:GillSans-Light;">305 N. University Street | West Lafayette | IN 47907 | USA</span></font></div><div><font class="ecxApple-style-span" color="#0000FF" face="Gill Sans"><span class="ecxApple-style-span" style="color:rgb(0, 0, 255);font-family:'Gill Sans';"><span class="ecxApple-style-span" style="color:rgb(0, 0, 255);font-family:'Gill Sans';">Mobile</span></span></font><font class="ecxApple-style-span" face="GillSans-Light"><span class="ecxApple-style-span" style="font-family:GillSans-Light;"><span class="ecxApple-style-span" style="font-family:GillSans-Light;"><span class="ecxApple-converted-space"> </span>+1 765 427 5484</span></span></font></div><div><font class="ecxApple-style-span" face="GillSans-Light"><br class="ecxkhtml-block-placeholder"></font></div></span></span></span></span></span></span></span><br class="ecxApple-interchange-newline"></span></div></span></div></span><br class="ecxApple-interchange-newline"></span><br class="ecxApple-interchange-newline">
</div>
<br></div> </div></body>
</html>