If you are talking about PICBasic, then a rotation will push bits out the end and lose them... they are replaced with zero's being pushed back in...
The result of an addition of two numbers will remain within the variable size you have decalred, and only the bottom eight bits (in a byte) or the bottom 16 bits (in a word) will remain.Code:' example 1... a var byte a=%11111111 a=a >> 1 ' a now contains %01111111 ' example 2... a var byte a=%11111111 a=a << 3 ' a now contains %11111000
If you need to check for an overflow, then you will need an additional line of code...Code:' example 3... a var byte b var byte c var byte b=255 c=1 a=b+c ' Result in a = 0 (zero) ' example 4... a var word b var byte c var byte b=255 c=1 a=b+c ' Result in a = 256
Code:' example 5... a var byte b var byte c var byte overflow var byte b=255 c=1 a=b+c if a < b then overflow=1 else overflow=0




Bookmarks