tackling sqlite byte-order problem
David Relson
relson at osagesoftware.com
Wed Feb 9 13:39:45 CET 2005
On Wed, 09 Feb 2005 10:52:46 +0100
Matthias Andree wrote:
> David Relson <relson at osagesoftware.com> writes:
>
> >> I wonder if we should add a new token .ENDIAN32 (from datastore) that
> >> stores the hex value 0x01020304 in natural byte order and use that to
> >> figure if the database is byteswapped.
> >
> > .ENDIAN32 sounds fine to me. Clearly sqlite needs it. Is it of value
> > for the other DB's we support?
> >
> > Alternatively, since we _know_ that .WORDLIST_VERSION is of form
> > YYYYMMDD, we can split it into YYYY and MMDD and know that YYYY>MMDD is
> > correct while MMDD>YYYY indicates is_swapped.
>
> Is YYYYMMDD stored in BCD format? That's news to me, I thought it was in
> digital, and in that case, the distinction between YYYY and MMDD doesn't
> fall on a byte boundary.
My bad. It's binary, not BCD. Splitting would be "divide by 10000" and
check for reasonable results. As a sanity check I wrote the little
program I've attached. It does an endian swap then prints the dates and
their yyyy and mmdd components. Perhaps it's useful; perhaps it's not.
Run like so:
gcc -o yyyymmdd yyyymmdd.c ; yyyymmdd ; yyyymmdd 20020820 ; yyyymmdd 21050209
David
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: yyyymmdd.c
URL: <https://www.bogofilter.org/pipermail/bogofilter-dev/attachments/20050209/7957d525/attachment.c>
More information about the bogofilter-dev
mailing list