Results 1 to 1 of 1

Thread: Array Extensions

  1. #1

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Array Extensions

    Some useful Array/IEnumerable/etc. extensions. The "extension" part, of course, requires VS 2008 or higher. Enjoy!

    Code:
    Imports System.Runtime.CompilerServices
    
    Public Module Extensions
        <Extension(), DebuggerStepThrough()> _
        Public Sub BitRotateLeft(ByVal arr() As Byte)
            If arr.Length = 0 Then Exit Sub
    
            Dim carry As Byte = arr(0) >> 7
            For i As Integer = arr.Length - 1 To 0 Step -1
                Dim newCarry As Integer = arr(i) >> 7
                arr(i) = arr(i) << 1 Or carry
                carry = newCarry
            Next
        End Sub
    
        <Extension(), DebuggerStepThrough()> _
        Public Sub BitRotateLeft(ByVal arr() As Byte, ByVal amount As Integer)
            For i As Integer = 1 To amount
                arr.BitRotateLeft()
            Next
        End Sub
    
        <Extension(), DebuggerStepThrough()> _
        Public Sub BitRotateRight(ByVal arr() As Byte, Optional ByVal amount As Integer = 1)
            arr.BitRotateLeft(32 - amount Mod 32)
        End Sub
    End Module
    Last edited by minitech; Jun 20th, 2011 at 02:38 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width