User`s manual
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
76
mikroBASIC
MikroElektronika: Development tools - Books - Compilers
making it simple...
page
A div B
is the value of A divided by B rounded down to the nearest integer. The
mod operator returns the remainder obtained by dividing its operands. In other
words,
X mod Y = X – (X div Y) * Y.
If 0 (zero) is used explicitly as the second operand (i.e. X div 0), compiler will
report an error and will not generate code. But in case of implicit division by zero:
X div Y , where Y is 0 (zero), result will be the maximum value for the appropri-
ate type (for example, if X and Y are words, the result will be $ffff).
Destination will store the correct value only if it can properly represent the result
of the expression (that is, if result fits in the destination range). More details can
be found in chapter Assignment and Implicit Conversion.
mikroBasic is more flexible compared to standard Basic as it allows both implicit
and explicit type conversion. In mikroBasic, operator can take operands of differ-
ent type; refer to chapter Type Conversion for more details. You cannot combine
signed and unsigned data types in expressions with arithmetic operators.
Arithmetic Operators
Overview
Mod and Div
Important
Arithmetics
and Data
Types
Operator Operation Operand Types Result Type
+ addition
byte, short, integer,
word, longint
byte, short, integer,
word, longint
- subtraction
byte, short, integer,
word, longint
byte, short, integer,
word, longint
* multiplication
byte, short, integer,
word
integer, word,
longint
div division
byte, short, integer,
word
byte, short, integer,
word
mod remainder
byte, short, integer,
word
byte, short, integer,
word