excel vba >>>

'Many programming languages have a bitwise zero-fill right-shift operator: >>>
'VBA does not. However, it can be emulated in a performant function:

Public Function ShiftRightZeroFill&(ByVal n&, Optional ByVal shifts& = 1)
    Dim d&
    If shifts = 0 Then ShiftRightZeroFill = n: Exit Function
    If n And &H80000000 Then
        shifts = shifts - 1
        n = (n And &H7FFFFFFF) \ 2 Or &H40000000
    End If
    Select Case shifts
        Case 0:  d = n
        Case 1:  d = n \ 2&
        Case 2:  d = n \ 4&
        Case 3:  d = n \ 8&
        Case 4:  d = n \ 16&
        Case 5:  d = n \ 32&
        Case 6:  d = n \ 64&
        Case 7:  d = n \ 128&
        Case 8:  d = n \ 256&
        Case 9:  d = n \ 512&
        Case 10: d = n \ 1024&
        Case 11: d = n \ 2048&
        Case 12: d = n \ 4096&
        Case 13: d = n \ 8192&
        Case 14: d = n \ 16384&
        Case 15: d = n \ 32768
        Case 16: d = n \ 65536
        Case 17: d = n \ 262144
        Case 18: d = n \ 262144
        Case 19: d = n \ 524288
        Case 20: d = n \ 1048576
        Case 21: d = n \ 2097152
        Case 22: d = n \ 4194304
        Case 23: d = n \ 8388608
        Case 24: d = n \ 16777216
        Case 25: d = n \ 33554432
        Case 26: d = n \ 67108864
        Case 27: d = n \ 134217728
        Case 28: d = n \ 268435456
        Case 29: d = n \ 536870912
        Case 30: d = n \ 1073741824
        Case 31: d = &H0&
    End Select
    ShiftRightZeroFill = d
End Function
    
'----------------------------------------------------------------------------    
    
'Don't be off-put at the size of the function. This is many times faster than 
'any other VBA function that carries out bitwise zero-filled right-shfits.
'The hard-coded values are much faster than calculating with exponentiation.

MsgBox ShiftRightZeroFill&(-9, 2)		<--displays:  1073741821
    

'NB: Remember that VBA Longs are signed.

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
excel vba := excel vba &lt;&gt; excel vba and &lt;&gt; vba excel excel programing language visual basic programming in excel programming vba programming in excel vb codes for excel function basics of vba in excel vb macro vba programing launguage write vba excel beginners excel vba MS Excel programming script in visual basic called visual basic a=excel easy vba define excel vba basic vba VBA Script vba programming for excel VBA. excel programming language development with visual basic excel vb macros use visual basic for excel vba programming excel visual basic application in excel excel vaba vba -4146 vba language basics a simple vba program visual basic tutorial excel excel vb macro vba vba programming language excel programing excel programing with vba excel macro language programmin language vba coding in excel vba coding can you program excel how to write vba progrmaming in excel microsoft visual basic in excel vba ** excel vba program hoiw to code in vba &lt;&gt; vba macro exel macro with exel vba visual basic in excel vba macro using vba in excel excel vba macro vba basic excel vba code microsoft excel vba use vba excel learn visual basic for excel VBA Micors vba tutorial visual basics macro excel microsoft excel coding language vba what for vba tutorial excel what is vba in excel vba excel excel vbscript tutorial excel programming working with vba in excel vba in excel vba and exel vba macros excel coding visual basic visual basic excel programming excel learn excel vba excel how vba excel coding learn vba what is excel vba programming language of microsoft excel vba for excel visual basic for excel excel vba excel vba use of &lt;&gt; excel vba programming in excel vba vba programming vba basics VBA visual basic macros excel excel visual basic simplest vba code what is vba excel vba customxml cdata excel-vba &gt;&gt;&gt; excel vba &gt;&gt;&gt;
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source