David McAfee (Home)
dmcafee at pacbell.net
Wed Oct 29 17:20:40 CST 2003
John if you are doing this in MS SQL SErver, theres pretty decent help in there about the bitwise comparison.. ~ (Bitwise NOT) Performs a bitwise logical NOT operation for one given integer value as translated to binary expressions within Transact-SQL statements. Syntax ~ expression Arguments expression Is any valid MicrosoftR SQL ServerT expression of any of the data types of the integer data type category, or of the binary or varbinary data type. expression is an integer that is treated and transformed into a binary number for the bitwise operation. Result Types Returns an int if the input values are int, a smallint if the input values are smallint, a tinyint if the input values are tinyint, or a bit if the input values are bit. Remarks The bitwise ~ operator performs a bitwise logical NOT for the expression, taking each corresponding bit. The bits in the result are set to 1 if one bit (for the current bit being resolved) in expression has a value of 0; otherwise, the bit in the result is cleared to a value of 1. The ~ bitwise operator can be used only on columns of the integer data type category. Important When performing any kind of bitwise operation, the storage length of the expression used in the bitwise operation is important. It is recommended that you use the same number of bytes when storing values. For example, storing the decimal value of 5 as a tinyint, smallint, or int produces a value stored with different numbers of bytes. tinyint stores data using 1 byte, smallint stores data using 2 bytes, and int stores data using 4 bytes. Therefore, performing a bitwise operation on an int decimal value can produce different results as compared to a direct binary or hexidecimal translation, especially when the ~ (bitwise NOT) operator is used. The bitwise NOT operation may occur on a variable of a shorter length that, when converted to a longer data type variable, may not have the bits in the upper 8 bits set to the expected value. It is recommended that you convert the smaller data type variable to the larger data type, and then perform the NOT operation on the result. Examples This example creates a table with int data types to show the values, and puts the table into one row. USE master GO IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'bitwise') DROP TABLE bitwise GO CREATE TABLE bitwise ( a_int_value tinyint NOT NULL, b_int_value tinyint NOT NULL ) GO INSERT bitwise VALUES (170, 75) GO This query performs the bitwise NOT on the a_int_value and b_int_value columns. USE MASTER GO SELECT ~ a_int_value, ~ b_int_value FROM bitwise Here is the result set: --- --- 85 180 (1 row(s) affected) The binary representation of 170 (a_int_value or A, below) is 0000 0000 1010 1010. Performing the bitwise NOT operation on this value produces the binary result 0000 0000 0101 0101, which is decimal 85. (~A) 0000 0000 1010 1010 ------------------- 0000 0000 0101 0101 -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com]On Behalf Of John Colby Sent: Wednesday, October 29, 2003 2:48 PM To: Access Developers discussion and problem solving Subject: RE: [AccessD] brain farts I tried this and it's giving me errors. This is the actual built up SQL statement. UPDATE MsysForms SET [FRM_GroupOpen] = [FRM_GroupOpen] ~ 4, [FRM_GroupVisible] = [FRM_GroupVisible] ~ 4, [FRM_GroupEdit] = [FRM_GroupEdit] ~ 4, [FRM_GroupAddRec] = [FRM_GroupAddRec] ~ 4, [FRM_GroupDelRec] = [FRM_GroupDelRec] ~ 4 WHERE (((MsysForms.FRM_ID) In (28,34,33,35,32,29,31,30))); Is that as you understand it to be used? Likewise it didn't like the vertical bar. John W. Colby www.colbyconsulting.com -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Stuart McLachlan Sent: Wednesday, October 29, 2003 5:04 PM To: Access Developers discussion and problem solving Subject: RE: [AccessD] brain farts Sure you can. You need to use the "bitwise" oprators, not the logical operators: & (Bitwise AND), | (Bitwise OR) , ^ (Bitwise Exclusive OR) ~ (Bitwise NOT) On 29 Oct 2003 at 15:37, James Barash wrote: > John, > As far as I know, you cannot use bitwise functions in an SQL statement. > You need to create a function to do the comparison. For example: > > Public Function BinaryOr(ByVal val1 As Long, ByVal val2 As Long) As Long > BinaryOr = (val1 Or val2) > End Function > > Create one function for each binary comparison you need or you could > create one function and pass the operator you want to use. > Hope this helps. > > James Barash > > > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Colby > Sent: Wednesday, October 29, 2003 2:12 PM > To: AccessD > Subject: [AccessD] brain farts > > > Folks, > > I'm trying to do boolean operations in a query. I have a table with bit > mapped fields such that the long integer has bits "on" or 1 in specific > circumstances. Now I want to OR in other numbers in SQL. I have a SQL > statement that looks like: > > SELECT MsysForms.FRM_GroupOpen, ([MsysForms]![frm_GroupOpen] Or 1) AS > NewVal FROM MsysForms; > > regardless of the value contained in the field frm_GroupOpen, the NewVal > is always -1 for an OR or an AND of any other value, and 0 for an XOR. > > If I have a 4 in the field, 4 OR 1 should give me 5, but it is giving me > -1. I believe it is "interpreting" it and saying it is true. But why? > > John W. Colby > www.colbyconsulting.com > > > _______________________________________________ > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > > _______________________________________________ > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com -- Lexacorp Ltd http://www.lexacorp.com.pg Information Technology Consultancy, Software Development,System Support. _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com