The & operator deals with the binary format of a decimal number. So 10 & 9 = 8 because
1010 (10)
1001 (9)
=====
1000 (8)
This previous example runs fine. But when I try to do 010 & 010 I expect the result to be 10. However I get 8. Can anyone explain to me why this is happening ?
10is considered decimal, because it's default. When it starts with a0, it's considered octal.0xis considered as hexadecimal. As has been pointed out to me, there's no C standard for binary, although some compilers (such as GCC) consider0bas binary representation.