Home > DeveloperSection > Forums > How to Convert NSData length into MB in iOS?
monica frank
monica frank

Total Post:10

Posted on    January-12-2016 4:48 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 4460  View(s)
Rate this:

Can anyone tell me how can I convert NSData length which is in bytes into  megabytes.
I want to print that value in NSLog() like this:

NSLog(@"Data length: %u MB", imageData.length);

above code will print bytes but I want to print length in MB.
for example: Data length: 8 MB

Please help me.

Tarun Kumar

Total Post:214

Posted on    January-13-2016 6:28 AM

As we know that- in 1KB=1024 bytes and 1024KB in 1Megabyte.
So, we can use your code like this:
NSLog(@"Data length: %u MB",(imageData.length/1024/1024));
Above we are provided the simplistic approach.

Modified On Jan-13-2016 07:01:11 AM

Don't want to miss updates? Please click the below button!

Follow MindStick