separate,reverse,regroup

only_lonely

Board Regular
Joined
Aug 24, 2006
Messages
80
given a hex strings 57 31 7c 4d 30 30 30 30 30 31 35 36 33 7c 7c 54 45 53 54 4c
1. separate into 4 bytes per group
57 31 7c 4d
30 30 30 30
30 31 35 36
33 7c 7c 54
45 53 54 4c

2. reverse it from MSB to LSB way
57 31 7c 4d = 4d 7c 31 57
30 30 30 30 = 30 30 30 30
30 31 35 36 = 36 35 31 30
33 7c 7c 54 = 54 7c 7c 33
45 53 54 4c = 4c 54 53 45

3. regroup
4d 7c 31 57 30 30 30 30 36 35 31 30 54 7c 7c 33 4c 54 53 45
 

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
PS you could incorporate grpLen as an argument

Code:
Option Base 0
Function separateReverseRegroup(ByVal strHex As String, grpLen As Integer) As String
    Dim spl As Variant, grpCount As Integer
    spl = Split(Trim(strHex), " ")
    grpCount = Int(UBound(spl) / grpLen) + 1
    If (UBound(spl) + 1) Mod grpLen <> 0 Then
        separateReverseRegroup = "Not in groups of " & grpLen
    Else
        For i = 0 To grpCount - 1
            For j = grpLen - 1 To 0 Step -1
                separateReverseRegroup = separateReverseRegroup & spl(i * grpLen + j) & " "
            Next j
        Next i
        separateReverseRegroup = Trim(separateReverseRegroup)
    End If
End Function
So you'd call the function with

=separateReverseRegroup(A2,4)
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Watch MrExcel Video

Forum statistics

Threads
1,108,481
Messages
5,523,195
Members
409,504
Latest member
Joshcurrie

This Week's Hot Topics

Top