Keep going!!!
(What do they call those 'machines' that take the most indirect route to accomplish something? Remember that kids game 'Mousetrap'?)
My next submission:
Code:
testnumber var word
onescount var byte
onescount1 var byte
loopvar var byte
testnumber = 12345
main:
for loopvar = 0 to 15 'counts bits set in the testnumber
if testnumber.0[loopvar] = 1 then
onescount = onescount + 1
endif
next loopvar
testnumber = testnumber >> 1 'shifts the LSB out
testnumber = testnumber << 1 'shifts a zero bit back in
for loopvar = 0 to 15 'recounts bits set in the testnumber
if testnumber.0[loopvar] = 1 then
onescount1 = onescount1 + 1
endif
next loopvar
if onescount = onescount1 then lcdout "EVEN" 'if the number of set bits is the same, its even
if onescount <> onescount1 then lcdout "ODD"
STOP 'please stop!
Bookmarks