Add new comment

Opérateurs au niveau du bit

Example et résultats :

SELECT 
   CONVERT(bit, 1) & CONVERT(bit, 0) AS [1 and 0],
   CONVERT(bit, 0) & CONVERT(bit, 1) AS [1 and 0],
   CONVERT(bit, 1) & CONVERT(bit, 1) AS [1 and 1],
   CONVERT(bit, 0) & CONVERT(bit, 0) AS [0 and 0]
SELECT   
   CONVERT(bit, 1) | CONVERT(bit, 0) AS [1 or 0],
   CONVERT(bit, 0) | CONVERT(bit, 1) AS [1 or 0],
   CONVERT(bit, 1) | CONVERT(bit, 1) AS [1 or 1],
   CONVERT(bit, 0) | CONVERT(bit, 0) AS [0 or 0]
SELECT   
   CONVERT(bit, 1) ^ CONVERT(bit, 0) AS [1 nor 0],
   CONVERT(bit, 0) ^ CONVERT(bit, 1) AS [0 nor 1],
   CONVERT(bit, 1) ^ CONVERT(bit, 1) AS [1 nor 1],
   CONVERT(bit, 0) ^ CONVERT(bit, 0) AS [0 nor 0]
SELECT   
   ~CONVERT(bit, 0) AS [not 0],
   ~CONVERT(bit, 1) AS [not 1]

Résultat :

1 and 0 1 and 0 1 and 1 0 and 0
------- ------- ------- -------
0       0       1       0
 
1 or 0 1 or 0 1 or 1 0 or 0
------ ------ ------ ------
1      1      1      0
 
1 nor 0 0 nor 1 1 nor 1 0 nor 0
------- ------- ------- -------
1       1       0       0
 
not 0 not 1
----- -----
1     0