czue
asked on
C# byte[] to hex string conversion inconsistency with Guid
I am trying to figure out why I am having inconsistencies converting byte[]'s to Guids / hex strings.
I have the following code:
byte[] bytes = [A 32-bit byte array]
string guid1 = ByteUtility.HexStringFromB yteArray(b ytes);
string guid2 = new Guid(bytes).ToString("N");
what I will see is (i don't care about the casing - just the out of order of the first 16 chars):
guid1 = 9C1D55DB53FA3F45889D6DC114 CABB6B
guid2 = db551d9cfa53453f889d6dc114 cabb6b
Here is the method in question:
public static string HexStringFromByteArray(byt e[] bytes) {
string s = "";
foreach (byte b in bytes) {
s += string.Format("{0:X2}", b);
}
return s;
}
thanks
I have the following code:
byte[] bytes = [A 32-bit byte array]
string guid1 = ByteUtility.HexStringFromB
string guid2 = new Guid(bytes).ToString("N");
what I will see is (i don't care about the casing - just the out of order of the first 16 chars):
guid1 = 9C1D55DB53FA3F45889D6DC114
guid2 = db551d9cfa53453f889d6dc114
Here is the method in question:
public static string HexStringFromByteArray(byt
string s = "";
foreach (byte b in bytes) {
s += string.Format("{0:X2}", b);
}
return s;
}
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER