how can i generate a unique int from a unique string?

后端 未结 6 1425
生来不讨喜
生来不讨喜 2020-12-24 09:32

I have an object with a String that holds a unique id . (such as \"ocx7gf\" or \"67hfs8\") I need to supply it an implementation of int hascode() which will be unique obvio

6条回答
  •  再見小時候
    2020-12-24 10:19

    represent each string character by a five-digit binary digit, eg. a by 00001 b by 00010 etc. thus 32 combinations are possible, for example, cat might be written as 00100 00001 01100, then convert this binary into decimal, eg. this would be 4140, thus cat would be 4140, similarly, you can get cat back from 4140 by converting it to binary first and Map the five digit binary to string

提交回复
热议问题