How can i convert/calculate bits per second (bps) to a readable size format like 10 Mbps, 7 Gbps, 5 Tbps, 4 Pbps, 3 Ebps...etc in iOS.
Best
Objective-C
- (NSString *)convertBitrateToHumanReadable:(long long)bytes {
    NSByteCountFormatter * formatter = [[NSByteCountFormatter alloc] init];
    return [formatter stringFromByteCount:bytes];
}
func convertBitrateToHumanReadable(bytes: Int64) -> String { ByteCountFormatter().string(fromByteCount: bytes) }
Swift 5
func convertBitrateToHumanReadable(bytes: Int64) -> String {
    let formatter = ByteCountFormatter()
    return formatter.string(fromByteCount: bytes)
}
You can append ps (per second) to result if you wish.
note that this answer is based on bytes instead of bits and each byte equals 8 bits....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With