$ echo $(( 255 ))255$ echo $(( 33 ))33$ echo $(( ~33 ))-34$ echo $(( ~255 ))-256$ and my kernel is:$ uname -aLinux HOSTNAME 3.2.0-40-generic-pae #64-Ubuntu SMP Mon Mar 25 21:44:41 UTC 2013 i686 i686 i386 GNU/LinuxQUESTION: ~ is for negating the number AFAIK. But why does ~33 produce -34 and why does ~255 produce -256?
Why does $(( ~33 )) produce -34?
bash;shell;arithmetic
The man page of bash says:   ! ~    logical and bitwise negationSigned numbers are usually stored in Two's complement representation:...-4 = 1100-3 = 1101-2 = 1110-1 = 1111 0 = 0000 1 = 0001 2 = 0010 3 = 0011...This means if you take a number like 2 it is bitwise interpreted as 0010. After bitwise negation this becomes 1101, which is the representation of -3.