473,385 Members | 1,535 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,385 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 3348
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.