Ted:
        VFP has functions to do all this work(bitset(), bitclear() and
bittest()! I'm changing it to Q(16) from integer, we're up to 60 odd
logical values and no end in sight. The reason *not* to use additional
integer fields is that we'd incur the additional overhead of developing
the logic to determine the field names as well. With a single field, all
I have to do is add another #DEFINE <bitposition> <offset> to my header
file.
        It seems a no-bit set varbinary value can be created by the
following udf:

Function vbEmpty
Lparameters nLength
Return createbinary(replicate(chr(0),nLength))

Bitwise operations don't seem to work correctly in this scenario unless
the initial, default value is set correctly.

-Lew

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Ted Roche
Sent: Friday, December 15, 2006 2:57 PM
To: [EMAIL PROTECTED]
Subject: Re: Bitwise operations and varbinary fields

On 12/15/06, Lew Schwartz <[EMAIL PROTECTED]> wrote:

> My current app records numerous logical values and, since I've just 
> run out of available bit locations in my integer field,

How many bits are you storing? You can store 31 or 32 bit (depending on
whether you can control sign) in a 4 byte integer field.

> I thought I'd change it to Q(10).

>From what?
>
> Q: Is there a more efficient way to do this?

Use separate logical fields. No coding required. Coding and processing
is typically a lot more expensive than disk space. Unless you have some
other retriction you didn't mention.

If you must use binary storage, use masks to query the values and UDFs
to get and set them.

Example. Hypens added for readability. In binary,

YourVal     = 0000-0000-0000-0000-0000-0000-0000-0000
Yourmask = 0000-0000-0000-0000-1000-0000-0000-0000

(your value is stored in the 15th postiion, counting from the right and
starting at zero, not one)

#DEFINE MySetting15Mask = 2^15

define function IsMyValueSet(valuetotest, mask) returns
BITAND(valuetotest, mask) <> 0

define function SetMyValue(valueholdingsets, mask) returns
BITOR(valueholdingsets, mask)

> Q:How to set an all bits off default value?

Default 0 if they're all define false.
#DEFINE a value if every other one is true:

#DEFINE MyDefault 2^31+2^29+2^27+...

(for extra bonus points, use one #DEFINE for each position and define
all variables off that)

Example:

#DEFINE IsUSCitizen 29
#DEFINE HasClearance 28
#DEFINE HasTSClearance 27
...
#DEFINE HasClearanceMask 2^(HasClearance)

> Q:How to determine field width: len() and fsize() don't work, but 
> using
> afields(...) seems to be ok.

Not sure why you would need to. What is it you're trying to do?

--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com


[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to