Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To see if the input is in little Endian or not <a href="http://msdn.microsoft.com/en-us/library/system.bitconverter.islittleendian.aspx" rel="noreferrer">BitConverter.IsLittleEndinan()</a> helps.</p> <p>I just had to do this same thing and using Paul Smith's answer above I got it working with this code. Derived off his code but <strong>with a fix on last byte swap order</strong> and condensed to one flip ensuring guid.FlipEndian().FlipEndian() == guid.</p> <p>C# Code:</p> <pre><code>public static class Extensions { /// &lt;summary&gt; /// A CLSCompliant method to convert a big-endian Guid to little-endian /// and vice versa. /// The Guid Constructor (UInt32, UInt16, UInt16, Byte, Byte, Byte, Byte, /// Byte, Byte, Byte, Byte) is not CLSCompliant. /// &lt;/summary&gt; [CLSCompliant(true)] public static Guid FlipEndian(this Guid guid) { var newBytes = new byte[16]; var oldBytes = guid.ToByteArray(); for (var i = 8; i &lt; 16; i++) newBytes[i] = oldBytes[i]; newBytes[3] = oldBytes[0]; newBytes[2] = oldBytes[1]; newBytes[1] = oldBytes[2]; newBytes[0] = oldBytes[3]; newBytes[5] = oldBytes[4]; newBytes[4] = oldBytes[5]; newBytes[6] = oldBytes[7]; newBytes[7] = oldBytes[6]; return new Guid(newBytes); } } </code></pre> <p>VB.net code (Translated from online service):</p> <pre><code>Public NotInheritable Class Extensions Private Sub New() End Sub ''' &lt;summary&gt; ''' A CLSCompliant method to convert a big-endian Guid to little-endian ''' and vice versa. ''' The Guid Constructor (UInt32, UInt16, UInt16, Byte, Byte, Byte, Byte, ''' Byte, Byte, Byte, Byte) is not CLSCompliant. ''' &lt;/summary&gt; &lt;CLSCompliant(True)&gt; _ &lt;System.Runtime.CompilerServices.Extension&gt; _ Public Shared Function FlipEndian(guid As Guid) As Guid Dim newBytes = New Byte(15) {} Dim oldBytes = guid.ToByteArray() For i As var = 8 To 15 newBytes(i) = oldBytes(i) Next newBytes(3) = oldBytes(0) newBytes(2) = oldBytes(1) newBytes(1) = oldBytes(2) newBytes(0) = oldBytes(3) newBytes(5) = oldBytes(4) newBytes(4) = oldBytes(5) newBytes(6) = oldBytes(7) newBytes(7) = oldBytes(6) Return New Guid(newBytes) End Function End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload