将一个浮点数转换为一个IEEE745规范的二进制
public class FloatDemo {
public static void main(String[] args) {
String value = convert(100.2f);
System.out.println(value);
}
private static String convert(float num) {
int intVal = Float.floatToIntBits(num);
return intVal > 0 ? "0" + Integer.toBinaryString(intVal) : Integer.toBinaryString(intVal);
}
}
求32位整数在机器中的补码
public class IntDemo {
public static void main(String[] args) {
int a = 6576;
for (int i = 0; i < 32; i++) {
int t = (a & 0x80000000 >>> i) >>> (31 - i);
System.out.print(t);
}
}
}
网友评论