I am studying bitwise operations in bash and understand all the other operations, but this one. It will be a great help if someone can explain (with examples) what the negation (~) operator does in bitwise operations. Couldn't understand from what I read here and elsewhere. TIA!
$ echo $(( 255 )) 255 $ echo $(( 33 )) 33 $ echo $(( ~33 )) -34 $ echo $(( ~255 )) -256 $    and my kernel is:  $ uname -a Linux HOSTNAME 3.2.0-40-generic-pae #64-Ubuntu SMP Mon Mar 25 21:44:41 UTC 2013 i686 i686 i386 GNU/Linux     QUESTION: ~ is for negating the number AFAIK. But why does ~33 produce -34 and why does ~255 produce -256?
How do we show that equality holds in the triangle inequality $|a+b|=|a|+|b|$ iff both numbers are positive, both are negative or one is zero? I already showed that equality holds when one of the three conditions happens.