<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255); text-align: left;" dir="auto">
Yes, those constants are defaulting to integer, which can represent both negative and positive values. When you do your shl you're inadvertently causing them to go into the range that pascal thinks is negative.</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255); text-align: left;" dir="auto">
<br>
</div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255); text-align: left;" dir="auto">
The typed constant should fix it.</div>
<div id="ms-outlook-mobile-signature">
<div><br>
</div>
--<br>
Alexander Grotewohl<br>
<a href="https://dcclost.com" target="_blank">https://dcclost.com</a></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> fpc-pascal <fpc-pascal-bounces@lists.freepascal.org> on behalf of wkitty42@windstream.net <wkitty42@windstream.net><br>
<b>Sent:</b> Tuesday, March 24, 2020 11:49:33 AM<br>
<b>To:</b> fpc-pascal@lists.freepascal.org <fpc-pascal@lists.freepascal.org><br>
<b>Subject:</b> Re: [fpc-pascal] Range check error warning.</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On 3/23/20 8:08 PM, fredvs via fpc-pascal wrote:<br>
> const<br>
> foldhiddenbit = 7;<br>
> foldhiddenmask = 1 shl foldhiddenbit;<br>
> currentfoldhiddenbit = 6;<br>
> currentfoldhiddenmask = 1 shl currentfoldhiddenbit;<br>
> foldlevelmask = byte(not (foldhiddenmask or currentfoldhiddenmask));<br>
> -------->Here the warning<br>
> <br>
> I dont understand how the compiler can find -193 as value for<br>
> foldlevelmask...<br>
<br>
<br>
so let's work through it manually... with a little rambling because too much <br>
c0ffee...<br>
<br>
<br>
foldhiddenmask is 10000000 binary (128 decimal; 80 hex)<br>
currentfoldhiddenmask is 01000000 binary (64 decimal; 40 hex)<br>
<br>
ORing them gives 11000000 binary (192 decimal; c0 hex)<br>
applying the NOT gives 00111111 binary (63 decimal; 3f hex)<br>
<br>
so that seems to come out as expected but i found several online bitwise <br>
calculators that came with the same -193 answer that fpc returned... this seems <br>
to be related to a wrong field initialization of some kind or using the wrong <br>
size for the value...<br>
<br>
go here: <a href="http://easyonlineconverter.com/converters/bitwise-calculator.html">
http://easyonlineconverter.com/converters/bitwise-calculator.html</a><br>
place 11000000 in field 1<br>
leave field 2 blank<br>
select "NOT"<br>
click calculate<br>
<br>
<br>
this one, <a href="https://toolslick.com/math/bitwise/not-calculator">https://toolslick.com/math/bitwise/not-calculator</a> , gives the same
<br>
-193 result but you can also see that it is using 16 bits (word) instead of 8 <br>
bits (byte) so the top 8 zero bits are also NOTted which makes them ones and <br>
there's the error... 1111111100111111 == -193... so i tried to trick it and used <br>
16bits... damned thing prepended 8 more ones to the beginning... they're not <br>
respecting that this is a byte we're working with...<br>
<br>
i almost feel like telling both of them and the others i found that their <br>
calculators are broken pretty badly... so back to your immediate problem...<br>
<br>
<br>
apparently your byte() is not working as desired?<br>
<br>
perhaps byte() is in the wrong place? perhaps it should be<br>
foldlevelmask = not (byte(foldhiddenmask) or byte(currentfoldhiddenmask));<br>
<br>
perhaps the top 8 bits need to be cleared by forcing them to zeros somehow if <br>
the default size of a const is larger than a byte?<br>
<br>
perhaps it should be specified that all four of foldhiddenbit, foldhiddenmask, <br>
currentfoldhiddenbit, currentfoldhiddenmask are of byte instead of word or other?<br>
<br>
<br>
const<br>
foldhiddenbit : byte = 7;<br>
foldhiddenmask : byte = 1 shl foldhiddenbit;<br>
currentfoldhiddenbit : byte = 6;<br>
currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit;<br>
foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask);<br>
*or*<br>
foldlevelmask : byte = not (byte(foldhiddenmask) or byte(currentfoldhiddenmask));<br>
<br>
<br>
<br>
NOTE: i do not currently have FPC (or lazarus) installed so i haven't tested <br>
this in fpc... i needed some drive space a few weeks back and it was easiest to <br>
remove fpc and lazarus at the time... especially since i had four or five <br>
versions of each installed with full source code...<br>
<br>
<br>
-- <br>
NOTE: No off-list assistance is given without prior approval.<br>
*Please keep mailing list traffic on the list where it belongs!*<br>
_______________________________________________<br>
fpc-pascal maillist - fpc-pascal@lists.freepascal.org<br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</div>
</span></font></div>
</body>
</html>