I am trying to convert a hexadecimal number into binary and count the positions where the 1 are, but at the time of doing so, it does not show the 0 on the left side, so the position is affected.
For example, I have the hexadecimal number 28C28805 , when I convert it to binary I get this way * 00 * 10 1000 1100 0010 1000 1000 0000 0101 but when I run the program I shows this result 10 1000 1100 0010 1000 1000 0000 0101 where you omit the first two 00.
Is there any way to show those digits that by logic does not show?
Annex the code with which I currently work:
package examenbitmap;
import java.io.*;
import java.lang.*;
public class ExamenBitmap {
public static void main(String[] args) throws IOException
{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ingrese el bit primario: ");
String hex = bf.readLine();
System.out.println("Ingrese el bit secundario: ");
String hexa = bf.readLine();
int y = Integer.parseInt(hex,16);
int x = Integer.parseInt(hexa,16);
String bin = Integer.toBinaryString(y);
String binx= Integer.toBinaryString(x);
String biny= Integer.toBinaryString(y) + Integer.toBinaryString(x);
System.out.println("El valor del bitmap primario es: " + biny);
//System.out.println("El valor del bitmap secundario es: " + binx);
System.out.println("Posicion de cada uno en la cadena: ");
for(int i=0;i<biny.length();i++){
if ('1'==biny.charAt(i)) {
if (i>0){
System.out.print(",");
}
System.out.print(String.valueOf(i+1));
}
}
System.out.println("");
}
}