title: Calculate CRC-16/CCITT-FALSE in Google Apps Script
body: <p>I have VBA code that calculates the CRC16 CCITT value of a text string, and now I am planning to use it on a Google Sheet, but do not have any idea how to convert the VBA code to Google Apps Script.</p>
  <pre><code>Function crc_ccitt_ffff(strParam As String) As String
    Const CRC_POLY_CCITT       As Long = &amp;H1021&amp;
    Const CRC_START_CCITT_FFFF As Long = &amp;HFFFF&amp;
  
    Dim crc_tabccitt(0 To 255) As Long, crc As Long, b() As Byte, c As Long, i As Long, j As Long
                                                                            
                                                                           
    For i = 0 To 255
        crc = 0
        c = i * 256
        For j = 0 To 7
            If (crc Xor c) And 32768 Then
               crc = (crc * 2) Xor CRC_POLY_CCITT
            Else
               crc = crc * 2
            End If
            c = c * 2
            Next j
        crc_tabccitt(i) = crc
    Next i
                                                                            
    b = strParam
    crc = CRC_START_CCITT_FFFF
    For i = 0 To UBound(b) Step 2
        crc = (crc * 256) Xor crc_tabccitt(((crc \ 256) Xor b(i)) And 255)
        crc = ((crc \ 65536) * 65536) Xor crc
    Next i
    crc_ccitt_ffff = Hex(crc)
  End Function
  </code></pre>
  <p>Test vector:</p>
  <p><code>00020101021129370016A000000677010111021312345678901215802TH5406500.5553037646304</code></p>
  <p>Expected result: <code>3D85</code></p>