工作中慢慢接触架构方面的设计,内存使用、带宽预估等工作离不开基础类型与内存的换算,整理一份简单的代码,备忘遗失的基础。
public class ElementaryDateType {
private static final String TYPE = "type";
private static final String BIT_UNIT = "(bit)";
private static final String BYTE_UNIT = "(Byte)";
public static void main(String[] args) {
// 8 bit = 1 Byte
System.out.println(TYPE + "\t" + BIT_UNIT + "\t" + BYTE_UNIT);
System.out.print("Byte\t");
System.out.println(Byte.SIZE + "\t" + Byte.SIZE / 8);
System.out.print("Short\t");
System.out.println(Short.SIZE + "\t" + Short.SIZE / 8);
System.out.print("Integer\t");
System.out.println(Integer.SIZE + "\t" + Integer.SIZE / 8);
System.out.print("Long\t");
System.out.println(Long.SIZE + "\t" + Long.SIZE / 8);
System.out.print("Float\t");
System.out.println(Float.SIZE + "\t" + Float.SIZE / 8);
System.out.print("Double\t");
System.out.println(Double.SIZE + "\t" + Double.SIZE / 8);
System.out.print("Character\t");
System.out.println(Character.SIZE + "\t" + Character.SIZE / 8);
System.out.println("Boolean is 1 bit");
}
}
type(bit)(Byte)
Byte81
Short162
Integer324
Long648
Float324
Double648
Character162
Boolean is 1 bit