473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

128-bit GUID

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
1 3349
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Zulik | last post by:
Hello, I have a problem with MessageDigest MD5 in Java. I want to calculate the digest from a file, encode it in base64 and display it. Now, according to MD5 spec, digest shall be 128 bits so,...
28
by: dingbat | last post by:
I'm writing a "tabbed folder" nav bar. Site standards are graphical prettiness, CSS throughout, valid code, but accesibility is ignored where it conflicts with prettiness. The particular issue...
1
by: Jeff | last post by:
On occasions we have failures and in the db2diag.log this is in the log identifying the failure. Please let me know if I have this right. Obj={pool:1;obj:2;type:128} pool is the tablespace id...
4
by: wob | last post by:
Many thanks for those who responded to my question of "putting greek char into C string". In searching for an solution, I noticed that there are more than one version of "Extended ASCII...
2
by: Sam | last post by:
In our C++ program, we are using the system call to execute another C++ program synchronously. The program executed by system runs without error and returns back a 0. Under conditions we cannot...
3
by: Hamilton | last post by:
Hi there, I've seen this error appear a few times in newsgroups but unfortunately I haven't found one that actually provides a solution. I'm basically deploying a new website into an area at a...
1
by: Taber, Mark | last post by:
I posted this earlier, and got no responses. While using pg_dump and pg_restore (or attempting to restore, more precisely), the process failed because of a missing user, user '128'. I never...
9
by: haijin.biz | last post by:
why the following program using "char" gives me an infinite loop? If I change char to int, it works fine. #include <iostream> using namespace std; int main(int argc, char** argv) { for(char...
1
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
2
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.