title: Bit shift when there is no ... bit shift operator
body: <p>I have to implement a checksum (CRC16 CCITT) to verify the content of a file. 
  The checksum is rather simple to implement in C or Java thanks to &lt;&lt; and >> operators and the many examples available on the net. </p>
  
  <p>The thing is... my checksum computation has to be implemented in VBScript.</p>
  
  <p>My experience with this language is nearly null but from my understanding, there isn't anything provided to do bit shifting in VBScript. Therefore I rely on <strong>multiplications and divisions by two.</strong> It works well except with <strong>negative values</strong>.</p>
  
  <p>I ran few tests and I believe that VBScript handles its 16 bits integers with two's complement. </p>
  
  <p><strong>Q1:</strong> can someone confirm me this (two's complement in VBScript) ? I didn't find any precise information from MSDN website.</p>
  
  <p><strong>Q2:</strong> Is it possible to do a bit shift (right and left) with simple mathematical operations when the negative number is coded with two's complement ?</p>
  
  <p>.</p>
  
  <p>Thanks a lot, I'd really like to avoid a kludge like dealing with integers as arrays of '1' and '0' or calling some java / c app from VBScript.</p>
  
  <p><strong>EDIT</strong> thank you for the help, find below my implementation of a right shift in VBScript:</p>
  
  <pre><code>Function rightShift(value,bits)
      Dim res
  
      res = 65535 AND value
  
      If value&gt;=0 Then
         res = res \ (2^bits)
      Else If value=-1 Then
               res = rightShift(res + 32768, bits - 1)
           Else
               res = rightShift(value \ 2 + 32768, bits - 1)
           End If
      End If
  
      rightShift = res AND 65535
  End Function 
  </code></pre>
  
  <p>Note about the code above: value was sometimes exceeding the 16 bits therefore I had to mask the unused bits to avoid overflow (<code>AND 65535</code>).</p>