I need to convert numbers, positive and negative, to binary format - like this, 2 in "00000010" and -2 in "11111110", for example. I don't need more than 12 bits or so, so if the string is longer than I can just truncate the leading signed bits. It seems that it Integer.toBinaryString()will do positive numbers, but is there one that can do negatives?
source
share