Positron Compiler Documentation

Dig

Positron16 · Revision 1.1.3.5 · PDF page 335

Assignment Variable = Dig Value, Digit number

Returns the value of a decimal digit.

Value is an unsigned constant, 8-bit, 16-bit, 32-bit variable or expression, from which the digit number is to be extracted. Digit number is a constant, variable, or expression, that represents the digit to extract from value. (0 - 9 with 0 being the rightmost digit). Assignment Variable can be any valid variable type.

Device = 24FJ64GA002           ' Select the device to compile for
Declare Xtal = 16
Declare Hserial_Baud = 9600    ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Dim MyByte as Byte
Dim MyResult as Byte
RPOR7 = 3                       ' Make PPS Pin RP14 U1TX
MyByte = 124
MyResult = Dig MyByte, 1       ' Extract the second digit's value
HrsoutLn Dec MyResult           ' Display the value, which is 2
  Device = 24FJ64GA002
  Declare Xtal = 16
  Declare Hserial_Baud = 9600     ' USART1 Baud rate
  Declare Hrsout1_Pin = PORTB.14  ' Select the pin for TX with USART1

   Dim MyWord As Word = 1234
  Dim MyDigit0 As Byte
  Dim MyDigit1 As Byte
  Dim MyDigit2 As Byte
  Dim MyDigit3 As Byte
  RPOR7 = 3                       ' Make PPS Pin RP14 U1TX
'
' 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 335Open page in PDFOriginal PDF page 335