Positron Compiler Documentation

Dig

Positron8 · Revision 4.0.6.5 · PDF page 328

Variable = Dig Value, DigitNumber

Returns the value of a decimal digit.

Value is an unsigned constant, 8-bit, 16-bit, 32-bit integer variable or expression, from which the DigitNumber is to be extracted. DigitNumber is a constant, variable, or expression that represents the digit to extract from Value. (0 - 9 with 0 being the rightmost digit).

Device = 18F25K20             ' Select the device to use
Declare Xtal = 16             ' Set its frequency
Declare Hserial_Baud = 9600   ' Set the Baud rate for the HRsoutLn command

Dim MyValue as Byte
Dim MyDigit as Byte

MyValue = 124
MyDigit = Dig MyValue, 1      ' Extract the second digit's value
HRsoutLn Dec MyDigit          ' Transmit the value, which is 2
  Device = 18F25K20             ' Select the device to use
  Declare Xtal = 16             ' Set its frequency
  Declare Hserial_Baud = 9600   ' Set the Baud rate for the HRsoutLn command

   Dim MyWord As Word = 1234
  Dim MyDigit0 As Byte
  Dim MyDigit1 As Byte
  Dim MyDigit2 As Byte
  Dim MyDigit3 As Byte
'
' Extract the separate digits from a variable
'
  MyDigit0 = Dig MyWord, 0 ' Extract the first digit (right to left)
  MyDigit1 = Dig MyWord, 1 ' Extract the second digit (right to left)
  MyDigit2 = Dig MyWord, 2 ' Extract the third digit (right to left)
  MyDigit3 = Dig MyWord, 3 ' Extract the fourth digit (right to left)

  HRsoutLn "Raw Digit 3 = ", Dec MyDigit3
  HRsoutLn "Raw Digit 2 = ", Dec MyDigit2
  HRsoutLn "Raw Digit 1 = ", Dec MyDigit1
  HRsoutLn "Raw Digit 0 = ", Dec MyDigit0
'
' Convert the digits to ASCII by adding 48
'
  Inc MyDigit0, 48
  Inc MyDigit1, 48
  Inc MyDigit2, 48
  Inc MyDigit3, 48

  HRsoutLn "ASCII Digit 3 = ", MyDigit3
  HRsoutLn "ASCII Digit 2 = ", MyDigit2
  HRsoutLn "ASCII Digit 1 = ", MyDigit1
  HRsoutLn "ASCII Digit 0 = ", MyDigit0
View original PDF page 328Open page in PDFOriginal PDF page 328