Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Hash Codes: Can C# and J#/J++ values be reconciled?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith - 15 Aug 2005 19:41 GMT
Hello,

C# and J#/J++ return very different HashCodes for the same string.  Is there
a reliable and generic way to reconcile these values?  For example:

[C#]
string foo = "BOB";
int cFooHash = foo.HashCode;

[J#/J++]
String foo = "BOB;
int jFooHash = foo.getHashCode();

Is there a way to make cFooHash == jFooHash for any value of foo?

I have hashed stuff stored externally from a J++ app.  I could use J# to
process them, but I'd rather not add a dependency to the J# runtime.

Thanks!

Keith
Hibri - 16 Aug 2005 21:32 GMT
Hi,
The internal algorithms will differ from language to language. usually  
these hash codes are not meant to be portable.
If you want to generate truly portable hash codes you should try MD5 or  
SHA hashes. These hashes are generated using standard algorithms and will  
be the same regardless of the language generated.
In .Net the System.Cryptography namespace has classes to help with this.
C# and J# use the are .Net languages so a string in C# and J# could  
contain the same hash codes not too sure about this, maybe the exact  
implementations of the string object differ). J++ uses the Java runtime so  
the hash code would be different.
anyway if you really want to reliable hashcodes use MD5 or SHA. You could  
crate a new string class derived from string and override the HashCode  
method.

Hope this helps...

> Hello,
>
[quoted text clipped - 18 lines]
>
> Keith

Signature

.Hibri
www.hibri.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.