11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PICBASIC</strong> <strong>PLUS</strong> CompilerTo calculate constants for use with the */ instruction, put the whole number portion in theupper byte, then use the following formula for the value of the lower byte: -INT(fraction * 256)For example, take Pi (3.14159). The upper byte would be $03 (the whole number), andthe lower would be INT(0.14159 * 256) = 36 ($24). So the constant Pi for use with */would be $0324. This isn’t a perfect match for Pi, but the error is only about 0.1%.4.6. Divide ‘/’.The Divide operator (/) divides variables and/or constants, returning a 16-bit result.Works exactly as you would expect with unsigned integers from 0 to 65535.DIM Value1 as WORDDIM Value2 as WORDValue1 = 1000Value2 = 5Value1 = Value1 / Value2 ' Divide the numbers.PRINT @Value1 ' Show the result (200).4.7. Modulus ‘//’.The Modulus operator (//) returns the remainder left after dividing one value by another.Some division problems don’t have a whole-number result; they return a whole numberand a fraction. For example, 1000/6 = 166.667. Integer math doesn’t allow the fractionalportion of the result, so 1000/6 = 166. However, 166 is an approximate answer, because166*6 = 996. The division operation left a remainder of 4. The // returns the remainder ofa given division operation. Numbers that divide evenly, such as 1000/5, produce a remainderof 0: -DIM Value1 as WORDDIM Value2 as WORDValue1 = 1000Value2 = 6Value1 = Value1 // Value2 ' Get remainder of Value1 / Value2.PRINT @Value1 ' Show the result (4).17Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!