我如何在 iOS 中将每秒位数 (bps) 转换/计算为可读大小格式,例如 10 Mbps、7 Gbps、5 Tbps、4 Pbps、3 Ebps...等。
Best
Objective-C
- (NSString *)convertBitrateToHumanReadable:(long long)bytes {
NSByteCountFormatter * formatter = [[NSByteCountFormatter alloc] init];
return [formatter stringFromByteCount:bytes];
}
斯威夫特 5.1
func convertBitrateToHumanReadable(bytes: Int64) -> String { ByteCountFormatter().string(fromByteCount: bytes) }
Swift 5
func convertBitrateToHumanReadable(bytes: Int64) -> String {
let formatter = ByteCountFormatter()
return formatter.string(fromByteCount: bytes)
}
您可以附加ps
(每秒)如果您愿意的话可以得到结果。
note that this answer is based on bytes instead of bits and each byte equals 8 bits....
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)