首页 > 编程知识 正文

bit和byte换算关系,字节与位的换算

时间:2023-05-03 13:41:19 阅读:178542 作者:1294

b是Byte的缩写,意思是字节; b是比特的缩写,意思是比特; Kb是千比特,Kb是千字节; MB意味着兆字节;

换算关系:

1MB=1024KB=1024B*1024=1048576B;

8bit=1Byte

1024KB=1MB;

1024MB=1GB;

1024GB=1TB;

关于传输速率和网络速度:

通常,如果看到USB2.0接口的传输速度为480mbps,自然会认为其速度为480M/S,但实际上是错误的。 在某种意义上,mbps是mega bits per second的缩写,表示Mb/S (兆比特/秒),准确地理解应该为) 60MB/S,其中的换算关系如上所述,为18。

平时所说的100M的网速是指100Mbps(1024位左右),换算成12.5MB/S。 理论下载速度达到12.5MB/S秒。

计算硬盘容量:

厂家生产硬盘时,为了计算方便,1KB只有1000字节,1MB只有1000KB,1G只有1000MB。 请参阅。 请参阅。 请参阅。 请参阅。 请参阅。 所以,500G硬盘实际上

500 * 1000 * 1000 * 1000/1024 * 1024 * 1024=465.66 g

估算硬盘大小的常用方法:

出场大小(g ) 1000(1000 ) 1000/1024 ) 1024 ) 1024=实际硬盘大小(g ) ) ) ) ) ) ) ) ) ) ) )

/** * * @title * @date 2019年1月7日* @ authorniuchuang * @ param old _ unit转换前的文件单位* @param new_unit转换后的偏移@ REE am publicstaticlongunitconvert (long size,String old_unit,String new_unit ) { long new_size=0; string utils.is not blank (old _ unit ) string utils.is not blank (new _ unit ) ) old _ unit=old _ unit.to lower if (! OLD_unit.equals(new_unit ) (if ) ) _ unit _ bit.equals|file _ unit _ byte.equals file _ unit _ MB.equals file _ unit _ TB.equals (file _ unit _ byte.equals|| file _ unit _ kb.equals|| file _ unit _ equals new_unit ) ) /小单位为大单位if (file _ unit ) ) )至else if (file _ unit _ bit.equals (old _ unit ) file _ unit _ u unit ) else if (file _ unit _ bit.equals (old _ unit ) file _ unit _ GB.equals (new _ unit ) ) /位bit )千兆位GB size=else if (file _ unit _ byte.equals (old _ unit ) file _ unit _ kb.equals (new _ unit ) ) byte是千字节kbsize=) else if (file _ unit _ byte.equals (old _ unit ) file _ unit _ MB.equals (new _ unit ) ) byte )兆字节MBsize=)

.equals(old_unit) && FILE_UNIT_GB.equals(new_unit)) {//字节byte 转 千兆字节gb size=size/1024/1024/1024; }else if (FILE_UNIT_KB.equals(old_unit) && FILE_UNIT_MB.equals(new_unit)) {//千字节kb 转 兆字节mb size=size/1024; }else if (FILE_UNIT_KB.equals(old_unit) && FILE_UNIT_GB.equals(new_unit)) {//千字节kb 转 千兆字节gb size=size/1024/1024; }else if (FILE_UNIT_MB.equals(old_unit) && FILE_UNIT_GB.equals(new_unit)) {//兆字节mb 转 千兆字节gb size=size/1024; }else{//更多类型转换 boolean isRe=false; double sized=size; if (FILE_UNIT_BIT.equals(old_unit)) {//比特bit 转 字节byte sized=sized/8; old_unit=FILE_UNIT_BYTE; } isRe=(isRe || old_unit.equals(new_unit))?true:false; if (FILE_UNIT_BYTE.equals(old_unit) && !isRe) {//字节byte 转 千字节kb sized=sized/1024; old_unit=FILE_UNIT_KB; } isRe=(isRe || old_unit.equals(new_unit))?true:false; if (FILE_UNIT_KB.equals(old_unit) && !isRe) {//千字节kb 转 兆字节mb sized=sized/1024; old_unit=FILE_UNIT_MB; } isRe=(isRe || old_unit.equals(new_unit))?true:false; if (FILE_UNIT_MB.equals(old_unit) && !isRe) {//兆字节mb 转 千兆字节gb sized=sized/1024; old_unit=FILE_UNIT_GB; } isRe=(isRe || old_unit.equals(new_unit))?true:false; if (FILE_UNIT_GB.equals(old_unit) && !isRe) {//千兆字节gb 转 太字节tb sized=sized/1024; } size=(long) sized; } }else{//大单位转小单位 if (FILE_UNIT_BIT.equals(new_unit) && FILE_UNIT_KB.equals(old_unit)) {//千字节kb 转 比特bit size=size*8*1024; }else if (FILE_UNIT_BIT.equals(new_unit) && FILE_UNIT_MB.equals(old_unit)) {//兆字节mb 转 比特bit size=size*8*1024*1024; }else if (FILE_UNIT_BIT.equals(new_unit) && FILE_UNIT_GB.equals(old_unit)) {//千兆字节gb 转 比特bit size=size*8*1024*1024*1024; }else if (FILE_UNIT_BYTE.equals(new_unit) && FILE_UNIT_KB.equals(old_unit)) {//千字节kb 转 字节byte size=size*1024; }else if (FILE_UNIT_BYTE.equals(new_unit) && FILE_UNIT_MB.equals(old_unit)) {//兆字节mb 转 字节byte size=size*1024*1024; }else if (FILE_UNIT_BYTE.equals(new_unit) && FILE_UNIT_GB.equals(old_unit)) {//千兆字节gb 转 字节byte size=size*1024*1024*1024; }else if (FILE_UNIT_KB.equals(new_unit) && FILE_UNIT_MB.equals(old_unit)) {//兆字节mb 转 千字节kb size=size*1024; }else if (FILE_UNIT_KB.equals(new_unit) && FILE_UNIT_GB.equals(old_unit)) {//千兆字节gb 转 千字节kb size=size*1024*1024; }else if (FILE_UNIT_MB.equals(new_unit) && FILE_UNIT_GB.equals(old_unit)) {//千兆字节gb 转 兆字节mb size=size*1024; }else{//更多类型转换 boolean isRe=false; double sized=size; if (FILE_UNIT_TB.equals(old_unit) && !isRe) {//太字节tb 转 千兆字节gb sized=sized*1024; old_unit=FILE_UNIT_GB; } isRe=(isRe || old_unit.equals(new_unit))?true:false; if (FILE_UNIT_GB.equals(old_unit) && !isRe) {//千兆字节gb 转 兆字节mb sized=sized*1024; old_unit=FILE_UNIT_MB; } isRe=(isRe || old_unit.equals(new_unit))?true:false; if (FILE_UNIT_MB.equals(old_unit) && !isRe) {//兆字节mb 转 千字节kb sized=sized*1024; old_unit=FILE_UNIT_KB; } isRe=(isRe || old_unit.equals(new_unit))?true:false; if (FILE_UNIT_KB.equals(old_unit) && !isRe) {//千字节kb 转 字节byte sized=sized*1024; old_unit=FILE_UNIT_BYTE; } isRe=(isRe || old_unit.equals(new_unit))?true:false; if (FILE_UNIT_BYTE.equals(old_unit) && !isRe) {//字节byte 转 比特bit sized=sized*8; } size=(long) sized; } } new_size=size; }else{ throw new RuntimeException("不再转换范围,转换前单位["+old_unit+"],转换后单位["+new_unit+"]"); }}else{new_size=size;log.warn("相同单位无需转换,转换前单位["+old_unit+"],转换后单位["+new_unit+"]");}} return new_size; } /** * 旧单位是否比新单位小 * @title * @date 2019年1月7日 * @author niuchuang * @param old_unit * @param new_unit * @return */ private static boolean isFileUnit(String old_unit,String new_unit){ if (old_unit.equals(FILE_UNIT_BIT) && !new_unit.equals(FILE_UNIT_BIT)) {return true;}else if (old_unit.equals(FILE_UNIT_BYTE) && (!new_unit.equals(FILE_UNIT_BIT) && !new_unit.equals(FILE_UNIT_BYTE))) {return true;}else if (old_unit.equals(FILE_UNIT_KB) && (!new_unit.equals(FILE_UNIT_BIT) && !new_unit.equals(FILE_UNIT_BYTE)&& !new_unit.equals(FILE_UNIT_KB))) {return true;}else if (old_unit.equals(FILE_UNIT_MB) && (!new_unit.equals(FILE_UNIT_BIT) && !new_unit.equals(FILE_UNIT_BYTE)&& !new_unit.equals(FILE_UNIT_KB) && !new_unit.equals(FILE_UNIT_MB))) {return true;}else if (old_unit.equals(FILE_UNIT_GB) && (!new_unit.equals(FILE_UNIT_BIT) && !new_unit.equals(FILE_UNIT_BYTE)&& !new_unit.equals(FILE_UNIT_KB) && !new_unit.equals(FILE_UNIT_MB) && !new_unit.equals(FILE_UNIT_GB))) {return true;}else if (old_unit.equals(FILE_UNIT_TB) && (!new_unit.equals(FILE_UNIT_BIT) && !new_unit.equals(FILE_UNIT_BYTE)&& !new_unit.equals(FILE_UNIT_KB) && !new_unit.equals(FILE_UNIT_MB) && !new_unit.equals(FILE_UNIT_GB)&& !new_unit.equals(FILE_UNIT_TB))) {throw new RuntimeException("不支持该单位类型转换,转换前单位["+old_unit+"],转换后单位["+new_unit+"]");}else{return false;} }

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。