Interesting question! In a former life, I worked on addressable converter interfaces, and much was done with bitmaps...so I played a bit also...
Note the results if you execute the following select in your example:
select @a, @b, @c, cast(@a AS varbinary), cast(@b as varbinary), cast (@c as varbinary)
-2 -2 254 0xFFFFFFFE 0xFFFE 0xFE
Now you get to see the binary results...which still does not answer your question, but I betcha (as I head back to BOL) that the answer lies in there as the way the sign bit is interpreted in the larger two data types.
Betcha that the tinyint data type does not have a sign bit.
yep...that's it...from BOL:
So the issue is not so much that the bitwise operation actually WORKS any differently...what you are seeing is just the PRESENTATION differences between data types (the final select assumes you want the data interpreted in it's numeric value, not the bit-representation of the data in the variable....so you get a negative number because you have set the sign bit on with the bitwise operation you used on the larger data types (that have sign bits).
Originally Posted by BOL
In other words, the bitwise operator works exactly the same on all three data types, it just LOOKS like it works differently when you select it back to see the results (without casting, that is).
Last edited by TallCowboy0614; 09-06-06 at 18:53.
Non est ei similis.
I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them