Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I create a unique integer number based on a number of different values?

0
10 Posted

How do I create a unique integer number based on a number of different values?

0
10

Well, the trick is finding a sufficiently short number that represents the item in question. You can do a CRC but the result is never unique — just very, very unlikely that it will have the same CRC as something similar. You can always create a unique number by reducing the words (strings), dates, and numbers to serialized integers and then appending them together. In fact, if you store your strings as null-terminated bytes, then you can treat the string as a large number: e.g. let’s say I have the date January 1st, 2011, the word ‘the’ and the number 32. I can reduce that to: 2-0-1-1-0-1-0-1-‘t’-‘h’-‘e’-3-2 And then just take the byte equivalent of each element. In practice, however, it might make sense to express the date as a shorter integer (e.g. the number-of-days since the beginning of the epoch) and then appending that to the other string elements. Taking the byte equivalent of each decimal numeral would be storage-intensive.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123