In Java, we can use Integer.toBinaryString(int) to convert a byte to a binary string representative. Review the Integer.toBinaryString(int) method signature, it takes an integer as argument and returns a String. Integer.java public final class Integer extends Number implements Comparable<Integer>, Constable, ConstantDesc { public static String toBinaryString(int i) { return toUnsignedString0(i, 1); } //… } If […]

Read more Java – How to convert a byte to a binary string

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