Weird shift right behaviour in simulator

kennethm

New Member
Perhaps someone can shed some light on this ...

The following shift code does not work as intended when run in the simulator, as b0 returns 128 instead of 127.

Code:
#picaxe 40X1
setfreq 16em

let b0 = 255
b0 = b0 >> 1 'This returns 128

'Sanity check
let b0 = 255
b0 = b0 / 2 'This returns 127 as expected
This behaviour seems to appear only when 255 is loaded into b0. Am i missing something ?

I have not tried this code in a PICAXE 40X1 yet though.
 
Last edited:

Technical

Technical Support
Staff member
Yes, its a simulation rounding error bug on this value which we will correct in the next release, thanks for highlighting it. The real chip will work fine as (unlike the computer) it never uses any fractions anyway!
 
Top