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
 
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)
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top