Convert BigEndian to UInt32 without use memblock?

HI :smiley:,
I read a file using BigEndian, and I put it in array named DWORD:
DWORD() As UInt32

Is perfect to me use bigEndian with my many methods.
But I have a problem if I need to convert a value to Int.

Infact I can’t use:
Var qtaSections As UInteger = DWORD(5) because the Integer value is not convert correctly.

So, I ā€œcopied / modifiedā€ with this code:

Var mb As New MemoryBlock(4)
mb.LittleEndian = False
mb.UInt32Value(0) = DWORD(5) 'Here, in DWORD(5), an integer value: &h04000000
mb.LittleEndian = True
Var qtaSections As UInteger = mb.UInt32Value(0) 'Now in qtaSections I have a realy 4 number

Is working, but…
…is there a fastly method to convert the DWORD(5) BigEndian to Integer without use memory block for switch to LittleEndian ?

It could be done with bitwise operations, but I don’t know if it would be any faster.

Untested, but it would look something like this:

Public Function ReverseEndian(i As int32) as int32
  dim i0 As uint32 = And(&h000000ff, i)*&h10000000
  dim i1 As uint32 = And(&h0000ff00, i)*&h1000
  dim i2 As uint32 = And(&h00ff0000, i)\&h1000
  dim i3 As uint32 = And(&hff000000, i)\&h10000000
  return i0+i1+i2+i3
End Function

I’ve always used MemoryBlocks for this type of conversion. They seem pretty fast and efficient.