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




Reply With Quote
