数据存储换算
在字节、千字节、兆字节、吉字节、太字节等之间换算。
数据存储转换器在位、字节、千字节、兆字节、吉字节、太字节和拍字节之间转换数字存储大小。在比较硬件规格、规划云存储预算、分析文件大小或解读数据库容量报告时,了解存储单位至关重要。
在任意单位中输入值,工具立即显示所有其他单位的等效值。该工具支持二进制 (IEC) 标准(1 KiB = 1024 字节)和十进制 (SI) 标准(1 KB = 1000 字节),因为不同的环境和操作系统使用不同的约定。
常见转换包括了解特定吉字节数包含多少兆字节、计算带宽时文件以位为单位有多大,或将以太字节表示的磁盘容量转换为格式化后实际提供的吉字节数。
常见问题
代码实现
# Data storage conversion (decimal SI units)
# 1 KB = 1,000 bytes, 1 MB = 1,000,000 bytes, etc.
def bytes_to_kb(b: float) -> float:
return b / 1_000
def bytes_to_mb(b: float) -> float:
return b / 1_000_000
def bytes_to_gb(b: float) -> float:
return b / 1_000_000_000
def bytes_to_tb(b: float) -> float:
return b / 1_000_000_000_000
# Binary IEC units (used by OS)
# 1 KiB = 1,024 bytes, 1 MiB = 1,048,576 bytes, etc.
def bytes_to_kib(b: float) -> float:
return b / 1024
def bytes_to_mib(b: float) -> float:
return b / (1024 ** 2)
def bytes_to_gib(b: float) -> float:
return b / (1024 ** 3)
# Examples
print(bytes_to_gb(1_000_000_000)) # 1.0 (1 TB drive, decimal)
print(bytes_to_gib(1_000_000_000)) # 0.9313 (same drive, binary/OS view)
print(bytes_to_mb(500_000_000)) # 500.0 MBComments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.