comparison - Android SQLiteDatabase - Storing and Comparing Large Numbers -
I am trying to store a very large number which is larger than 8 bytes, INTEGER and real field type. I need to be able to return the lines in which this field contains a number which I specify is less than or greater than any other large number. I'm not sure how to do this. It seems that my only option is to store it as text, but then when I & gt; And & lt; In a question, comparison of TEXT is not equal to a numerical comparison (numbers are not the same number of numbers). I have tried to use Blob or to store my large number as a byte array, but there is no benefit. Padding numbers with zero so that they do not have the same number of digits in fact work because I do not know how big the number can be. Thanks for any help appreciated!
For storage, there is only one option text or blob, so you need to give your numbers the So much so that lexicographical and numerical commands are only
For unsigned numbers, you can use a mechanism similar to SQLite4.
Let's say the encoding bytes A0, A1, A2, ..., A8.
If between 0 and 240, the result is A0's value. If A is between 241 and 248, the result is 240+ 256 * (A0-241) + A1.
So A0 is 249, then the result is 2287 + 256 * A1 + A2.
So A0 is 250 then the result is a 3-byte big A1..A3 -endian integer.
So the A0 is 251 then the result is A4. Byte is a 4-byte large endian as A1..A4.
So A0 is 252 so the result is a 5-byte big A1..A5 -endian integer.
So A0 is 253 then the result is A1..A6 as a 6-byte large endian integer.
So A0 is 254, so the result is a 7-byte big A1..A7 -andian integer.
If A0 is 255 then the result is A1aA8 8-byte as Big-endian integer.The above is designed for all 64-bit numbers. The extension of the mechanism for a large number is trivial, unless you are not upper bound.
If numbers can be signed, you will have to divide the
A0 range in the half, and use the first half for negative numbers.
If you do not have to do computation, then you can do the same principle to store ASCII digits instead of binary values. That is, use a prefix with a fixed length that specifies the length of the number, then the number. 0 ... 0001 | | 9
0001: If your number is not greater than 9999 points, then you can use a prefix length of four, like 0002. 10 ... 0002 | 99 0003 | 100 ... 0060 | 321741185926535897932384626433832795281828459045235360287471
If you need negative values here, then you must select an additional prefix for the negative / positive number that will sort correctly (
- The ASCII order of /
+ is incorrect, so you are better than
n /
p ), and you should use a prefix like 9999 รข ???? Length for negative numbers so that small negative numbers contain a small prefix.
Comments
Post a Comment