I am trying to print a Long in Binary, but it keeps cutting off 0
's. Is there a way to force it to show all bits?
This is my code:
long l = 1;
System.out.println(Long.toBinaryString((long)l));
Returns as mentioned only 1
due to removed 0
's i wish to maintain:
0000 0000 0000 0000 0000 0000 0000 0001
Thanks in advance.
My temporary nasty solution:
public String fillZeros(Long value)
{
String str = Long.toBinaryString((long) value);
String temp;
temp = str;
while(temp.length() < 32) {
temp = "0" + temp;
}
return temp;
}