Picbasic has no idea about negative numbers, anything goes below 0 gets deducted from 65535.
Picbasic has no idea about negative numbers, anything goes below 0 gets deducted from 65535.
Re-read the single line I sent. I was not talking about PBP. I'm talking about representation of integers in a binary system. Read this article: https://www.cs.cornell.edu/~tomf/not.../twoscomp.html What most software developers do when they want to know when the variable goes "below zero", is look at the most significant bit. If it is high, the number is negative, if it is low, the number is positive. Since you are using a word, then your largest positive number will be 32768.
And since here is PBP forum, not general representation forum, I'm asking how to deal with this in PBP![]()
Will this work for you?
iflag var bit
let iflag =0
reader:
adcin 0,Z
pause 100
IF Z>100 AND Z<130 THEN I=I+5
IF Z<100 and iflag = 0 THEN I=I-5 'only if iflag = 0 it's OK to substract
if i>255 then i=255
if i<5 then i=0
if i = 0 then let iflag = 1 'if i hits 0 put up a flag
if i >= 5 then let iflag = 0 'once i hits 5 or more, reset the flag
HPWM 2,I,10000
XY=I
gosub decoder
goto reader
Try this:
if Z.15 = 1 then
Z = 0
endif
Last edited by Dick Ivers; - 22nd June 2020 at 21:09.
In your original code, changeto thisCode:IF Z<100 THEN I=I-5Code:IF Z<100 AND I>=5 THEN I=I-5
Bookmarks