Review the following Java example to convert a negative integer in binary string back to an integer type. String binary = Integer.toBinaryString(-1); // convert -1 to binary // 11111111 11111111 11111111 11111111 (two’s complement) int number = Integer.parseInt(binary, 2); // convert negative binary back to integer System.out.println(number); // output ?? The result is NumberFormatException! Exception […]

Read more Java – Convert negative binary to Integer

In Java, Sign extension will kick in if we are doing the following stuff: Widening primitive conversion – Cast from one type to another, which involves increasing the bits of the original type, for example, cast byte (8 bits) to int (32 bits). Bitwise right shift by n bit >> n. The sign extension is […]

Read more Java Sign Extension