I am trying to write a bitwise calculator in java, something that you could input an expression such as ~101 and it would give back 10 however when i run this code
The toString() method interprets its argument as a signed value.
To demonstrate binary operations its better to use Integer.toBinaryString()
. It interprets its argument as unsigned, so that ~101 is output as 11111111111111111111111111111010.
If you want fewer bits of output you can mask the result with &.