我写这个输出来有的五位,有的32位,怎么整?
public class binary { public static void main(String args[])
{
byte p,q;
int r;
p=47;
q=-47;
r=p|q;
System.out.println(Integer.toBinaryString(p));
System.out.println(Integer.toBinaryString(q));
System.out.println(Integer.toBinaryString(r));
}
}
public class binary { public static void main(String args[])
{
byte p,q;
int r;
p=47;
q=-47;
r=p|q;
System.out.println(Integer.toBinaryString(p));
System.out.println(Integer.toBinaryString(q));
System.out.println(Integer.toBinaryString(r));
}
}
StringBuffer str =null;
str = new StringBuffer(Integer.toBinaryString(number).toString());
if(str.length() < 8){
for(int i =0;i<8-str.length()+1;i++){
str = str.insert(0,"0");
}
}if(str.length() > 8){
str =new StringBuffer(str.substring(str.length()-8,str.length()));
}
else{
;
}
return str.toString();
}
public static void main(String args[]) {
byte p, q;
int r,x;
p = 47;
q = -47;
r = p | q;
x = 128;
Test t = new Test();
System.out.println(t.refineNumber(p));
System.out.println(Integer.toBinaryString(p));
System.out.println(Integer.toBinaryString(q));
System.out.println(t.refineNumber(q));
System.out.println(Integer.toBinaryString(r));
System.out.println(t.refineNumber(r));
System.out.println(t.refineNumber(x));
}}
byte p, q;
int r;
p = 47;
q = -47;
r = p | q;
System.out.println(toIntegerBinaryString(p));
System.out.println(toIntegerBinaryString(q));
System.out.println(toIntegerBinaryString(r));
}public static String toIntegerBinaryString(int num) {
char[] bits = new char[Integer.SIZE];
for (int i = bits.length - 1; i >= 0; --i) {
bits[i] = ((num & 1) == 0) ? '0' : '1';
num >>>= 1;
}
return new String(bits);
}