什么是创建一个简短的哈希值的最佳方式,类同什么微小的网址呢? [英] What's the best way to create a short hash, similiar to what tiny Url does?

查看:342
本文介绍了什么是创建一个简短的哈希值的最佳方式,类同什么微小的网址呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用MD5哈希值,但我想找到的东西,将创建一个较短的哈希只使用[AZ] [AZ] [0-9]。它仅需要是大约5-10个字符长。

I'm currently using MD5 hashes but I would like to find something that will create a shorter hash that uses just [a-z][A-Z][0-9]. It only needs to be around 5-10 characters long.

有什么在那里,已经这样做了?

Is there something out there that already does this?

更新:

我喜欢的CRC32散列。有没有计算它在.NET中的一个干净的方式?

I like the CRC32 hash. Is there a clean way of calculating it in .NET?

UPDATE2:

我使用的是从乔提供的链接CRC32功能。我怎么能转换成UINT上面定义的角色?

I'm using the CRC32 function from the link Joe provided. How can I convert the uInt into the characters defined above?

推荐答案

.NET字符串对象有一个GetHash code()函数。它返回一个整数。 它转换为十六进制,然后到8个字符的字符串。

.NET string object has a GetHashCode() function. It returns an integer. Convert it into a hex and then to an 8 characters long string.

像这样:

string hashCode = String.Format("{0:X}", sourceString.GetHashCode());

更多关于是:<一href="http://msdn.microsoft.com/en-us/library/system.string.gethash$c$c.aspx">http://msdn.microsoft.com/en-us/library/system.string.gethash$c$c.aspx

更新:添加了备注从上面的链接,以这样的回答:

UPDATE: Added the remarks from the link above to this answer:

的GetHash code的行为是依赖于它的实现,   从公共语言运行库的一个版本可能会发生变化   另一个。一个原因,这可能发生的是,以提高性能   的GetHash code。

The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common language runtime to another. A reason why this might happen is to improve the performance of GetHashCode.

如果两个字符串对象是相等的,则GetHash code方法返回   相同的值。但是,没有一个唯一的哈希code值   每个唯一的字符串值。 不同的字符串可以返回相同的哈希   code。

If two string objects are equal, the GetHashCode method returns identical values. However, there is not a unique hash code value for each unique string value. Different strings can return the same hash code.

备注对调用者

由GetHash code返回的值是依赖于平台。它不同于上   在32位和64位版本的.NET Framework。

The value returned by GetHashCode is platform-dependent. It differs on the 32-bit and 64-bit versions of the .NET Framework.

这篇关于什么是创建一个简短的哈希值的最佳方式,类同什么微小的网址呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆