Public feed
#2vFJvYEQrB
# estimate.py —— 数制转换与存储容量估算验证脚本# 单位约定:1 MB = 10^6 B,1 MiB = 2^20 B,1 GB = 10^9 B,1 GiB = 2^30 Bdef show_num_systems(): print("=== 一、数制转换验证 ===") b = '10110101' print(f"int('{b}', 2) = {int(b, 2)}") # 期望 181 print(f"hex(255) = {hex(255)}") # 期望 0xff print(f"bin(0x1A) = {bin(0x1A)}") # 期望 0b11010 print(f"int('1A', 16) = {int('1A', 16)}") # 期望 26def photo_size(w=1920, h=1080, depth=24): bits = w * h * depth bytes_ = bits / 8 return bits, bytes_, bytes_ / 1e6, bytes_ / 2**20def audio_size(minutes=4, sr=44100, bits=16, ch=2): seconds = minutes * 60 bits_total = sr * bits * ch * seconds bytes_ = bits_total / 8 return bits_total, bytes_, bytes_ / 1e6, bytes_ / 2**20def video_size(hours=2, mbps=8): seconds = hours * 3600 bits_total = mbps * 1e6 * seconds bytes_ = bits_total / 8 return bits_total, bytes_, bytes_ / 1e9, bytes_ / 2**30def iphone_shot_size(w=2868, h=1320, depth=24): bits = w * h * depth bytes_ = bits / 8 return bits, bytes_, bytes_ / 1e6, bytes_ / 2**20def report(name, bits, bytes_, dec, bin_): print(f"\n{name}: {bits:,} bit = {bytes_:,.0f} B " f"≈ {dec:.2f} MB/GB ≈ {bin_:.2f} MiB/GiB")if __name__ == '__main__': show_num_systems() print("\n=== 二、存储容量估算 ===") report("1920×1080×24bit 未压缩照片", *photo_size()) report("4分钟 44.1kHz/16bit 双声道音频", *audio_size()) report("2小时 8Mbps 视频", *video_size()) report("iPhone 16 Pro Max 截图 2868×1320×24bit 未压缩", *iphone_shot_size())