Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "Yes" a value of -1 in MS Access database?

Tags:

sql

ms-access

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.

like image 797
supermitch Avatar asked Jan 11 '12 22:01

supermitch


People also ask

What is yes or no in Access?

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.

What is a yes no database?

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.

What are values in Access?

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.

What is data value in MS Access?

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.


1 Answers

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.

like image 158
Olivier Jacot-Descombes Avatar answered Oct 17 '22 12:10

Olivier Jacot-Descombes