[AccessD] [Spam] Left and right shift

Stuart McLachlan stuart at lexacorp.com.pg
Wed Apr 7 16:44:29 CDT 2010


Since a Shift is mainly used as a machine optimized way to multiply/divided by powers of two 
those functions seem a bit redundant.

I'd just use    Value = Value * 2 ^ Shift   and   Value = Value  \  2 ^ Shift 
(any decent complier should optimise those to shifts internally)

-- 
Stuart


On 7 Apr 2010 at 11:16, Jim Dettman wrote:

> FYI,
> 
>   Here's a couple routines I found to do bit shifts in VBA:
> 
> 
> Public Function shr(ByVal Value As Long, ByVal Shift As Byte) As Long
>     Dim i As Byte
>     shr = Value
>     If Shift > 0 Then
>         shr = Int(shr / (2 ^ Shift))
>     End If
> End Function
> 
> Public Function shl(ByVal Value As Long, ByVal Shift As Byte) As Long
>     shl = Value
>     If Shift > 0 Then
>         Dim i As Byte
>         Dim m As Long
>         For i = 1 To Shift
>             m = shl And &H40000000
>             shl = (shl And &H3FFFFFFF) * 2
>             If m <> 0 Then
>                 shl = shl Or &H80000000
>             End If
>         Next i
>     End If
> End Function
> 
> Jim.
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
> Sent: Wednesday, April 07, 2010 9:56 AM
> To: Access Developers discussion and problem solving
> Subject: [Spam] [AccessD] Left and right shift
> 
> I thought we have a >> and << operator in Access - shift left and shift
> right.  When I try to use it 
> I get a compile error.
> 
>    IntPtr = IntPtr >> 2
> 
> Do we not have this operator?  I can't find it listed in an operator in
> help.
> 
> -- 
> John W. Colby
> www.ColbyConsulting.com
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com





More information about the AccessD mailing list