Home > Software engineering >  Storage Size Conversion from multiples of 1000 to multiples of 1024
Storage Size Conversion from multiples of 1000 to multiples of 1024

Time:02-18

I have a task which I have to complete with Java. The task is to convert given Hard drive size from multiples of 1000 to multiples of 1024. Suppose if an input is 752 MB, the output will be 717.16 MiB.

My problem is i am unable to find the math solution for this task.

Here is the data set of conversion.

enter image description here

CodePudding user response:

The issue is actually quite easy once you count how many bytes a MB vs a MiB represents. Afterwards you just multiply it through.

MB = 1000 * KB = 1000 * 1000 B = 1,000,000 B
MiB = 1024 * KiB = 1024 * 1024 B = 1,048,576 B

x MB = y MiB

x * MB / MiB = y
x / 1.048576 = y

You might be confusing yourself by thinking of it as base-10 vs base-2. Really there is no base-x conversion at all since what you want to do it a simple unit conversion from MB to MiB.

  • Related