[FRPythoneers] 24 bit number

Jorge Seidel jorge at purecode.com
Mon Feb 3 11:56:02 MST 2003


John

You might try reading them in as three 32-bit integers and assigning them to
a Long as a 96 bit integer.  Then use a bit mask to pull out the four 24-bit
integers from that field.  That would probably be easier than some other
solutions since the 96 bits aligns with both the 24 and 32 bit integer
fields.  I haven't tried this (I don't have any 24-bit data fields).

x = [32-bit integer from ISAM]
y = [another 32-bit integer]
z = [one more 32-bit integer]

i = 0L
i = z
i = i<<32 + y
i = i<<32 + x
#depends on bit ordering which one you load first and how you shift
mask = 0xFFFFFF
a = i & mask
i = i>>24
b = i & mask
i = i>>24
c = i & mask
d = i >> 24

This is pseudo code intended to show the process  8-)

Jorge

----- Original Message -----
From: "John M. Purser" <jmpurser at attbi.com>
To: <frpythoneers at lists.community.tummy.com>
Sent: Monday, February 03, 2003 11:24 AM
Subject: [FRPythoneers] 24 bit number


> I'm reading an ISAM database with Python and for most of the files it
works
> fine.  However I have 83 fields (out of several thousand total) that are
> (believe it or not) 24 bit integers!  Most are unsigned but a few are
> signed.  I've approached the problem by decoding them as a 16 bit signed
or
> unsigned integer and an 8 bit integer using the struct module.  I'll
> multiply the 16 bit nuber by 256 then add it to the 8 bit number and put
it
> in MySql as a 32 bit number.
>
> Can anyone think of a better approach?
>
> John Purser
>
>
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe |
FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
>




More information about the FRPythoneers mailing list