Java中的字节和比特

1 byte = 8 bit
bit 代表物理电路的两个状态,on 和 off , on 是1 ,off 是0
byte 是计算机中最小的单位。

public String formatFileSize(long file) {
DecimalFormat df = new DecimalFormat("#.00");
String fileSizeString = "";
if (file < 1024) {
fileSizeString = df.format((double) file) + "B";
} else if (file < 1048576) {
fileSizeString = df.format((double) file / 1024) + "K";
} else if (file < 1073741824) {
fileSizeString = df.format((double) file / 1048576) + "M";
} else {
fileSizeString = df.format((double) file / 1073741824) + "G";
}
return fileSizeString;
}

https://www.jianshu.com/p/b3699d73142e

你可能感兴趣的:(Java中的字节和比特)