Encoding a 5-character string into a unique and repeatable 32-bit integer

I have not thought about this yet, so I might be a stupid question.

How can I take a unique ASCII character string and convert it to a unique and reproducible (i.e., should be the same every time) 32-bit integer?

Any ideas?

+3
source share
6 answers

, ASCII (.. 127), 7 35 . 32- 35 , ; , 7 ASCII. , , , - , , , . , CRC-32. -, ​​ MD5 SHA-1, 32 ; , , , .

(, -, , , - ), , , 32- .

+3

- ([A-Z] [0-9]), 36.

+3

ASCII, , 5 , 40 . ( ) , 35 ASCII 32 .

+2

ascii 0-255, 8 ... 32 4 , 5. , , .

( 128-255) ascii ( ascii 0-127) 7 , 3 (7 * 5 = 35 32 .

+2

- 5 N, N - ( ). .

, 32 5 , , 32 ^ (1/5) = 84 . , ASCII, ASCII ( > 127), 7 , - . 32 , , , , 95 .

11 . ASCII, , , .

+2

84 , . 0..83,

  intvalue = ((((char4*84+char1)*83+char2)*82+char3)*81+char0)
  char0 = intvalue % 84
  char1 = (intvalue / 84) % 84;
  char2 = (intvalue / (84*84)) % 84;
  char3 = (intvalue / (84*84L*84)) % 84;  
  char4 = (intvalue / (84*84L*84*84L) % 84;

, , - base-84 ; , base-64, .

+2

Source: https://habr.com/ru/post/1764535/


All Articles