位(bit)、字节(Byte)、MB(兆位)之间的换算关系 您所在的位置:网站首页 100mb等于多少bit 位(bit)、字节(Byte)、MB(兆位)之间的换算关系

位(bit)、字节(Byte)、MB(兆位)之间的换算关系

2023-11-29 03:50| 来源: 网络整理| 查看: 265

B是Byte的缩写,意思是字节;b是bit的缩写,意思是比特位;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,其中的换算关系如上,是1:8的关系。

  平时说的100M的网速,指的是100Mbps(1024比特位),换算过来,就是12.5MB/S。理论上的下载速度可以达到12.5MB/S。

硬盘容量的计算:

  厂商在制作硬盘的时候,为了计算方便,1KB只有1000Byte,1MB只有1000KB,1G只有1000MB。。。。。。所以,500G的硬盘实际上只有

  500*1000*1000*1000/1024*1024*1024 = 465.66G

  估计一块硬盘大小的通式:

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

/** * * @title * @date 2019年1月7日 * @author niuchuang * @param size * @param old_unit 转换前文件单位 * @param new_unit 转换后文件单位 * @return */ public static long unitConvert(long size,String old_unit,String new_unit){ long new_size=0; if (StringUtils.isNotBlank(old_unit) && StringUtils.isNotBlank(new_unit)) { old_unit=old_unit.toLowerCase().trim(); new_unit=new_unit.toLowerCase().trim(); if (!old_unit.equals(new_unit)) { if ((FILE_UNIT_BIT.equals(old_unit) || FILE_UNIT_BYTE.equals(old_unit) || FILE_UNIT_KB.equals(old_unit) || FILE_UNIT_MB.equals(old_unit) || FILE_UNIT_GB.equals(old_unit) || FILE_UNIT_TB.equals(old_unit)) && (FILE_UNIT_BIT.equals(new_unit) || FILE_UNIT_BYTE.equals(new_unit) || FILE_UNIT_KB.equals(new_unit) || FILE_UNIT_MB.equals(new_unit) || FILE_UNIT_GB.equals(new_unit) || FILE_UNIT_TB.equals(new_unit))) { if (isFileUnit(old_unit, new_unit)) {//小单位转大单位 if (FILE_UNIT_BIT.equals(old_unit) && FILE_UNIT_KB.equals(new_unit)) {//比特bit 转 千字节kb size=size/8/1024; }else if (FILE_UNIT_BIT.equals(old_unit) && FILE_UNIT_MB.equals(new_unit)) {//比特bit 转 兆字节mb size=size/8/1024/1024; }else if (FILE_UNIT_BIT.equals(old_unit) && FILE_UNIT_GB.equals(new_unit)) {//比特bit 转 千兆字节gb size=size/8/1024/1024/1024; }else if (FILE_UNIT_BYTE.equals(old_unit) && FILE_UNIT_KB.equals(new_unit)) {//字节byte 转 千字节kb size=size/1024; }else if (FILE_UNIT_BYTE.equals(old_unit) && FILE_UNIT_MB.equals(new_unit)) {//字节byte 转 兆字节mb size=size/1024/1024; }else if (FILE_UNIT_BYTE.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; } }

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有