By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

128-bit GUID

P: n/a
Hi all,
I've got this math problem... I feel a little bit silly but here it is, because it seems first year CS, but my memory fails me.

Sample Code:
Guid myGuid = new Guid("fccf281d-47bd-45c7-8f2b-a48d462d171b");
Int64 myGuidInt = BitConverter.ToInt64(myGuid.ToByteArray(),0);
this.textBox1.Text = myGuid.ToString();
this.textBox2.Text = myGuidInt.ToString();
Byte[] me = myGuid.ToByteArray();
this.textBox3.Text = "";
for (int ow = 0; ow < 16; ow++)
{
this.textBox3.Text += me[ow].ToString() + "-";
}
/*
This generates:
Int64: 5028066390298273821
ByteArray: 29-40-207-252-189-71-199-69-143-43-164-141-70-45-23-27
*/

Questions:
The math-by-hand way of doing this is how???
1. From the guid string "fccf281d-47bd-45c7-8f2b-a48d462d171b" to byte array? (Basically the internal working of ToByteArray())
2. From the byte array to Int64? (Something like (n1 * 16^0) + (n2 * 16^2) + ... maybe??)
3. Or from the guid string "fccf281d-47bd-45c7-8f2b-a48d462d171b" to it's bit representation? (01010101... all 128 of them).

Thank you much for any help you can give.
~Js.
Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Guid string is in hex.

You must convert each byte to hex string. For 1 byte there will be 2 hex chars.
Spearators '-' are added by 8, 4, 4, 4, and 12 bytes.
string retVal = "";
byte[] bytes = Guid.NewGuid().ToByteArray();
foreach(byte b in bytes){
retVal += b.ToString("x");
}

MessageBox.Show(retVal);

"John Smith" <.@.> wrote in message news:Pk*******************@twister.socal.rr.com...
Hi all,
I've got this math problem... I feel a little bit silly but here it is, because it seems first year CS, but my memory fails me.

Sample Code:
Guid myGuid = new Guid("fccf281d-47bd-45c7-8f2b-a48d462d171b");
Int64 myGuidInt = BitConverter.ToInt64(myGuid.ToByteArray(),0);
this.textBox1.Text = myGuid.ToString();
this.textBox2.Text = myGuidInt.ToString();
Byte[] me = myGuid.ToByteArray();
this.textBox3.Text = "";
for (int ow = 0; ow < 16; ow++)
{
this.textBox3.Text += me[ow].ToString() + "-";
}
/*
This generates:
Int64: 5028066390298273821
ByteArray: 29-40-207-252-189-71-199-69-143-43-164-141-70-45-23-27
*/

Questions:
The math-by-hand way of doing this is how???
1. From the guid string "fccf281d-47bd-45c7-8f2b-a48d462d171b" to byte array? (Basically the internal working of ToByteArray())
2. From the byte array to Int64? (Something like (n1 * 16^0) + (n2 * 16^2) + ... maybe??)
3. Or from the guid string "fccf281d-47bd-45c7-8f2b-a48d462d171b" to it's bit representation? (01010101... all 128 of them).

Thank you much for any help you can give.
~Js.
Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.