ShiftLeft vs multiply in .Net
Converting 2 bytes to a UINT16
Which is fastest? multiply or shiftLeft
Dim a As Byte = 3
Dim b As Byte = 7
Dim c As UInt16
For i = 0 To 100000
'c = a + b * 256
c = a + (CInt(b) << 8)
Next
Multiply wins, 10 % faster.
NB!
ShiftLeft << isn't calculated first so you need the () around
Shift left a byte, need to convert it to a uINT16 first.
c=1795
if you calc it
c=b<<8 +3 = 56
c=a+ b<<8 = 10
c=cint(b)<<8+3 = 14336
c=a+cint(b)<<8 = 2560
c=a+(cint(b) <<8) =1795
So I will stay away from ShiftLeft/Right !