We have an obsolete requirement to store what has recently transferred identifier values intto a type guidfor use in types of agnostic ID attributes (mostly old code that used the "globally unique" part guidto contain all possible identifiers in one column / field) .
In connection with this requirement needed to implement integer identifier entites in guida human-readable way . This is important and is currently what prevents me from working directly with byte values.
I currently have the following:
public static byte[] IntAsHexBytes(int value)
{
return BitConverter.GetBytes(Convert.ToInt64(value.ToString(), 16));
}
public static Guid EmbedInteger(int id)
{
var ib = IntAsHexBytes(id);
return new Guid(new byte[]
{
0,0,0,0,0,0,1,64,ib[7],ib[6],ib[5],ib[4],ib[3],ib[2],ib[1],ib[0]
});
}
int (value.ToString()), long (Convert.ToInt64(value.ToString(), 16)) long byte[] guid .
, int 42, 42 long, 66, 66 , guid :
"00000000-0000-4001-0000-000000000042"
int of 379932126 :
"00000000-0000-4001-0000-000379932126"
, , guid 12 , 42 ( 66).
30% -40% , new Guid(string), , , - .
, , , .
, , . , SO, , , , , .
0 int.MaxValue.
: , , :
string s = string.Format("00000000-0000-4001-0000-{0:D12}", id);
return new Guid(s);
, 30%.