I'm looking at linked data in MS Access.
The "Yes/No" fields contain the value -1 for YES and 0 for NO. Can someone explain why such a counter-intuitive value is used for "Yes"? (Obviously, it should be 1 and 0)
I imagine there must be a good reason, and I would like to know it.
In Access, a Yes/No field stores only two values: Yes or No. If you use a text box to display a Yes/No field, the value displays as -1 for Yes and 0 for No.
The Yes-No field is used to collect data with only a Yes or No answer. The field appears as a drop-down list on the canvas. The answer is stored in a database as a 1 or 0 where 1 = Yes and 0 = No. When writing Check Code, use (+) and (–) to indicate yes and no, respectively.
A value list is a hard-coded list of items that resides in the Row Source property of a list box or combo box control. In contrast, a lookup list takes its data from a lookup field (a field that uses a query to retrieve data from another table), and then loads that data into a combo box control.
A field's data type determines what kind of data it can store. MS Access supports different types of data, each with a specific purpose. The data type determines the kind of the values that users can store in any given field. Each field can store data consisting of only a single data type.
The binary representation of False is 0000000000000000 (how many bits are used depends on the implementation). If you perform a binary NOT operation on it, it will be changed to 1111111111111111, i.e. True, but this is the binary representation of the signed integer -1.
A bit of 1 at the most significant position signals a negative number for signed numbers. Changing the sign of a number happens by inverting all the bits and adding 1. This is called the Two's complement.
Let us change the sign of 1111111111111111. First invert; we get: 0000000000000000
Then add one: 0000000000000001, this is 1.
This is the proof that 1111111111111111 was the binary representation of -1.
UPDATE
Also, when comparing these values do not compare
x = -1 or
x = 1 instead, do compare
x <> 0 this always gives the correct result, independently of the convention used. Most implementations treat any value unequal zero as True.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With