For Tracy Allen
MichelB
Posts: 154
Dear Tracy, herewith attached a code derived from your App-Notes, BinaryLongDivisionDemo.bs2. I've added two lines to fix the range of number entered but it does not work when I enter for example -33000 for numerator even for denominator. Please help, I'm a beginner in programming. Thank you in advance and best regards.
Comments
The number must lie between -32768 and +32767, which is twos complement math for the BS2. So -33000 is out of range.
Also, on the Stamp, you can't do
IF (D < -32767) ....
For most purposes the Stamp treats all numbers as positive integers in the range of 0 to 65535.
The SDEC modifier in the debug statement allows the Stamp to accept a number like -1, but internally thosee numbers are represented as 65535.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
The following line IF (N < -32767) AND (N > 32767) THEN does not work when I enter -33000 for example. Try it.
You can't do what you want. Because the Stamp only does 16-bit arithmetic, SDEC will always accept signed values in the range -32768 to +32767 which will be treated like unsigned values in the range 32768 to 65535 (for -32768 to -1) and 0 to 32767. The IF statement cannot test for values outside this range (because everything is done in 16 bit unsigned arithmetic). The -32767 ($8001) in the IF statement is treated as 32769 ($8001).
The only way you can do what you want is to do your own conversion of characters ("0" to "9" and "-") to a number and include checking for invalid values. You can't use SDEC.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy