How to check if storage is calculated in base 10 or base 2 on Samsung devices?

34 views Asked by At

My Android app has a page that shows the phones free and total storage size. To get the storage information, I used the solution described in this stackoverflow answer.

This solution loops through all storage volumes, adds up the total space and returns the result in bytes.

I tested it on various devices and most of them returned an exact value that is divisible in base 10: For example, I got exactly 128000000000 bytes for an Asus 128GB device, and 32000000000 bytes for an older Pixel 32GB device.

But when I tested on a Samsung device, it returned 274877906944 bytes (256GB in base2). Now my app UI is showing 275GB total storage for the Samsung 256GB device which confuses the user. Am I wrong to assume that the physical bytes available on any Android device will always be divisible by base 10?

When I check the storage info on other thrid-party File Manager apps including Google Files, they all seem to display the correct storage information no matter which manufacturer.

So my question is: How do these apps know when to use base 10 or base 2 when calculating storage?

1

There are 1 answers

4
Gabe Sechan On

A simple hack- a base 2 number is never divisible by 10. So if the size % 10 is not 0, then it's a base 2 size.