Integer Modulus '//'
Syntax
Assignment Variable = Variable // Variable
Overview
Return the remainder left after dividing one unsigned or signed value by another.
Operands
Variable can be a constant, variable or expression. Assignment Variable can be any valid variable type.
Some division problems do not have a whole-number result; they return a whole number and a fraction. For example, 1000 / 6 = 166.667. Integer math doesn't allow the fractional portion of the result, so 1000 / 6 = 166. However, 166 is an approximate answer, because 166 * 6 = 996. The division operation left a remainder of 4. The // returns the remainder of a given division operation. Numbers that divide evenly, such as 1000 / 5, produce a remainder of 0.
Example 1
Device = 18F26K40 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
Dim Value1 as Word
Dim Value2 as Word
Value1 = 1000
Value2 = 6
Value1 = Value1 // Value2 ' Get remainder of Value1 / Value2.
HRsoutLn Dec Value1 ' Display the result (4).
Example 2
' 32-bit modulus
Device = 18F26K40 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
Dim wMyVar1 as Word
Dim dMyVar2 as Dword
wMyVar1 = 100
dMyVar2 = 99999
dMyVar2 = dMyVar2 // wMyVar1 ' Mod the numbers.
HRsoutLn Dec Value2 ' Display the result
Note.
The modulus operator does not operate with floating point constants or variables.
