Question:
How do I create a unique integer number based on a number of different values?
Cryasor
2011-03-18 10:02:07 UTC
I need to reduce (or encrypt) a number of words, dates and numbers to provide a single unique integer that represents the values. This is related to SQL Server, but any encryption method to create this check sum would be welcome. Thx
Three answers:
peteams
2011-03-19 15:27:17 UTC
SQL Server provides a function HashBytes that will convert a string into the kind of value you want, e.g.



SELECT HashBytes('SHA1', 'The string to hash')



The function supports MD2, MD4, MD5, SHA and SHA1. These are some of the standard and secure algroithms for doing this sort of thing.
Anonymous
2011-03-18 10:21:43 UTC
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.
?
2016-11-16 19:22:10 UTC
historic Sumerian Counting ( approximately 3000bc ) the classic human beings of Sumer, have been very forward thinking and progressed, they are theory to be the 1st human beings to have arise with the now basic device that we use at present of ordered positions interior the string. additionally usually used as powers. eg - Powers of Ten. - The Decimal device Powers of two - The Binary device Powers of 8 - The Octal device Powers of sixteen - The Hexadecimal device those structures use a small type of symbols and the area interior the string point out the magnitude. The positions are necessary and a place holder image is mandatory ( 0 0 ) for us, yet a shell shape for the Sumerians. the adaptation between our device and the Sumerians one is that we use base ten ( decimal ) and that they used base sixty ( sexagesimal ). So influential became their device, that we nonetheless use it at present. Time in minutes and seconds is counted in Sumerian Sexagecimal, and additionally angles in ranges ( which additionally are divided into ranges, minutes and seconds ). long in the past the greek mathematician Pythagarus, the Sumerians have been doing complicated arithmetic with angles. that is available that Pythagarus would have in trouble-free terms re got here across, or re translated previous Sumerian artwork. at present as quickly as we are utilising a sexagecimal device, instead of having sixty symbols for the assorted digit figures, we use a shorthand decimal with specific place markings denoted with apostrophes (') and speech marks ("). Eg: you should describe an attitude of 10 ranges 13 minutes and 5 seconds. as 10º 10' 5" As there are 60 angular seconds in an angular minute, and 60 angular minutes in a level, the entire circle of 360 ranges elegantly fits the entire type of minutes (360) in a million degree. meaning with this methodology that we are accurately dividing an entire circle into 360 x 360 = 129600ths 360 ranges minus a million 2nd is 359º59'fifty 9" the call of 360 to describe an entire circle is an marvelous decision, and lots greater effective than a metric type like 1000 or one hundred, simply by fact 360 could be divided precisely by utilising many distinctive components and is as a result lots greater effective than 1000. 360º = complete circle 180º = 0.5 a circle 120º = a third of a circle 90º = 1 / 4 of a circle 72º = a 5th of a circle 60º = a 6th of a circle - 40 5 º = an 8th of a circle 40 º = a 9th of a circle 36º = a 10th of a circle the 1st few best components of 360 are 7,11,13 meaning that lots of the very functional numbers as much as ten can certainly divide a circle with top ranges.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...