Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
This story was originally published on Medium
! for the Bitwise Negation (Bitwise NOT). This produces different results depends on the type.
As you see
!2 with the unsigned type returns
4294967293 and with the signed type returns
The bitwise negation on a signed integer returns the two’s complement as we saw previously in Rust signed two’s complement integer types.
Adding a Negative Number
The subtraction is the same as adding a negative number.
5 - 2 = 5 + (-2) = 3
This applies to binary as well.
0101 - 0010 = 0101 + (-0010) // (1) = 0101 + 1110 // (2) = 0011 // this is 3 in decimal number.
-0010 by finding the two’s complement of
0010 that is